Android - m3u8 视频流

Android - m3u8 video streaming

我正在我的应用程序中流式传输实时视频。我有一个 .m3u8 link,它在 vlc 播放器中完美运行。但是当我在我的应用程序中播放这个流时,视频的可视化被破坏了(见截图)。有谁知道,这可能是什么原因造成的?

编辑:我意识到这只发生在 Android 8.1.

为 .m3u8 尝试这个library,这将解决您的问题:

<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>

在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();
}

如果您使用 android studio 可以安装 NiceVieoPlayer 库,它功能强大并且可以加载到所有设备上。 你可以用它直播。

是一些中国人:D

祝你好运。