Android VideoView 直播电视流 (HLS)

Ern*_*s Z 5 android http-live-streaming android-videoview

我正在尝试为电视流媒体 (HLS) 开发应用程序。使用下面的代码我在 2.3.3、3.0 和 4.0.1 版本的 Android 设备上测试了流,但遇到了几个问题。在 Android 2.3.3 上,流播放时间超过 1 分钟,然后就停止了。在 Android 3.0 上它运行良好,在 Android 4.0.3 上它显示消息“无法播放此文件”(如果我没记错的话)。所以我的问题是:如何在这些设备的以太上播放流,而不会出现流播放问题?或者我在哪里可以阅读有关这些问题的解决方案的更多信息(尝试搜索但没有发现任何有用的信息)?

Main_Activity 中的代码:

    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    VideoView player = (VideoView)findViewById(R.id.player);
    String httpLiveUrl = "http://aj.lsops.net/live/aljazeer_en_high.sdp/playlist.m3u8";
    //for Android 2.3.3 I used httplive:// prefix
    player.setVideoURI(Uri.parse(httpLiveUrl));
    player.setMediaController(new MediaController(this));
    player.requestFocus();
    player.start();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}
Run Code Online (Sandbox Code Playgroud)

xml中的代码:

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

<VideoView
    android:id="@+id/player"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

对不起,如果我的英语很差。谢谢你。

小智 -1

将此代码插入 AndroidManifest.xml

<uses-permission android:name="android.permission.INTERNET" />
Run Code Online (Sandbox Code Playgroud)