Android的VideoView电视直播流(HLS) [英] Android VideoView live tv stream (HLS)

查看:2979
本文介绍了Android的VideoView电视直播流(HLS)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我'尝试开发电视流(HLS)的应用程序。使用code低于我的2.3.3,3.0和4.0.1版本的Andr​​oid设备测试流,但遇到了一些问题。
在Android 2.3.3流效力于> 1分钟,然后就停止。在Android 3.0它起着很好,在Android 4.0.3它显示消息此文件无法播放(如果我没记错的话)。
所以我的问题是:
我怎样才能对这些设备的醚播放流,而无需流播放的问题?或者,我在这里可以阅读更多有关解决这些问题(试图寻找但一无所获有用)?

I'am trying to develop app for tv streaming (HLS). Using code below I tested stream on 2.3.3, 3.0 and 4.0.1 version Android devices, but encountered several problems. On Android 2.3.3 stream plays for >1 minute and then just stops. On Android 3.0 it plays well and on Android 4.0.3 it displays message 'This file cannot be played' (if I remember correctly). So my question would be: How can I play stream on ether of these devices, without having stream playing problems? Or where can I read more about solutions to these problems (tried to search but found nothing useful)?

code在Main_Activity:

Code in 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;
}

code在XML:

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

很抱歉,如果我的英语很差。
谢谢。

Sorry if my english is poor. Thank You.

推荐答案

这不会解决所有的问题,流。但有一件事你应该做的就是调用 player.start()在MediaPlayer已准备就绪。所选答案这个SO帖子设置MediaPlayer对象上的侦听器,以便将运行开始()上prepared(MediaPlayer的MP)被调用。

This will not solve all the streaming issues. But one thing you should do is call player.start() when the MediaPlayer is ready. The selected answer to this SO post sets a listener on the MediaPlayer object so that it will run start() when onPrepared(MediaPlayer mp) is called.

这篇关于Android的VideoView电视直播流(HLS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆