2012-08-26 317 views
3

我试图开发电视流(HLS)的应用程序。使用下面的代码我测试了2.3.3,3.0和4.0.1版Android设备上的流,但遇到了几个问题。 在Android 2.3.3上,播放时间大于1分钟,然后停止播放。在Android 3.0上播放良好,在Android 4.0.3上显示消息'This file can not be playing'(如果我没有记错的话)。 所以我的问题是: 如何在这些设备的ether上播放流,而不会产生流播放问题?或者我可以在哪里阅读更多关于这些问题的解决方案(尝试搜索,但没有发现任何用处)?Android VideoView直播电视流(HLS)

守则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; 
} 

代码中的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> 

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

+0

请分享您如何播放直播印地语频道? –

回答

-1

插入此代码的AndroidManifest.xml

<uses-permission android:name="android.permission.INTERNET" /> 
0

这不会解决所有的问题,流。但是当MediaPlayer准备就绪时,您应该做的一件事是拨打player.start()。所选答案this SO post在MediaPlayer对象上设置侦听器,以便在调用onPrepared(MediaPlayer mp)时运行start()