简体   繁体   English

Android - m3u8视频流

[英]Android - m3u8 video streaming

I am streaming live video in my app. 我在我的应用中播放实时视频。 I have a .m3u8 link, which works perfectly in vlc player. 我有一个.m3u8链接,它在vlc播放器中运行得很好。 But when I am playing this stream in my app, the visualisation of video is damaged (see screenshot). 但是当我在我的应用程序中播放此流时,视频的可视化已损坏(请参见屏幕截图)。 Does anybody know, what could cause this? 有谁知道,这可能是什么原因造成的? 损坏的视频

EDIT: I realised that this occurs only on the Android 8.1. 编辑:我意识到这只发生在Android 8.1上。

Try this library for .m3u8 , this will solve your problem : 试试这个 .m3u8,这将解决您的问题:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:app="http://schemas.android.com/apk/res-auto"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

    <com.devbrackets.android.exomedia.ui.widget.VideoView
        android:id="@+id/video_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:useDefaultControls="true"/>

</RelativeLayout>

In Activity write below code 在Activity中写下面的代码

private VideoView videoView;

private void setupVideoView() {
    // Make sure to use the correct VideoView import
    videoView = (VideoView)findViewById(R.id.video_view);
    videoView.setOnPreparedListener(this);

    //For now we just picked an arbitrary item to play
    videoView.setVideoURI(Uri.parse("https://archive.org/download/Popeye_forPresident/Popeye_forPresident_512kb.m3u8"));
}

@Override
public void onPrepared() {
    //Starts the video playback as soon as it is ready
    videoView.start();
}

if you use android studio can impalement NiceVieoPlayer library , it powerfull and load on all devices. 如果你使用android studio可以穿透NiceVieoPlayer库,它会强大并加载所有设备。 you can stream live with it. 你可以直播它。

its some Chineses :D 它的一些中国人:D

goodluck. 祝好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM