Android支持HLS自适应比特率流?

时间:2014-12-19 02:40:27

标签: android http-live-streaming hls

我尝试使用HLS Adaptive Bitrate Streaming

我制作变体播放列表: 文件名是test.m3u8

#EXTM3U
#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=200000
low/low.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=311111
middle/middle.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=484444
high/high.m3u8

每个m3u8文件:

#EXTM3U
#EXT-X-VERSION:4
#EXT-X-TARGETDURATION:10
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:6.040000,
#EXT-X-BYTERANGE:158484@0
http://myserver/hls/Test/low/low.ts
#EXTINF:4.200000,
#EXT-X-BYTERANGE:121824@158484
http://myserver/hls/Test/low/low.ts
#EXTINF:10.000000,
#EXT-X-BYTERANGE:286512@280308
http://myserver/hls/Test/low/low.ts
..........
#EXT-X-ENDLIST

我的文件夹结构:

/hls/Test/test.m3u8
/hls/Test/low/low.m3u8
/hls/Test/middle/middle.m3u8
/hls/Test/high/high.m3u8

我的问题是:

iOS设备调用此网址(http://myserver/hls/Test/test.m3u8
视频播放工作。

Android设备会调用此网址(http://myserver/hls/Test/test.m3u8
视频无法播放 但是,我打电话给网址(http://myserver/hls/Test/low/low.m3u8
视频播放工作。

Android设备:samsung galaxy note 3

Android客户端来源:

@Override   
protected void onCreate(Bundle savedInstanceState) {    
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_video);

    initUI();
    Uri uri = Uri.parse("http://myserver/hls/Test/test.m3u8");

    MediaController mc = new MediaController(this);
    video_videoView.setMediaController(mc);

    video_videoView.setVideoURI(uri);
    video_videoView.start();
}   

private void initUI() { 
    video_videoView = (VideoView) findViewById(R.id.video_videoView);
}   

Android LogCat错误:

12-19 11:20:12.547: I/MediaPlayer(1704): path is null   
12-19 11:20:12.567: D/MediaPlayer(1704): setDataSource IOException happend :    
12-19 11:20:12.567: D/MediaPlayer(1704): java.io.FileNotFoundException: No content provider:   http://myserver/hls/Test/test.m3u8
12-19 11:20:12.567: D/MediaPlayer(1704): at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1053)
12-19 11:20:12.567: D/MediaPlayer(1704): at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:907)
12-19 11:20:12.567: D/MediaPlayer(1704): at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:834)
12-19 11:20:12.567: D/MediaPlayer(1704): at android.media.MediaPlayer.setDataSource(MediaPlayer.java:978)
12-19 11:20:12.567: D/MediaPlayer(1704): at android.widget.VideoView.openVideo(VideoView.java:338)
12-19 11:20:12.567: D/MediaPlayer(1704): at android.widget.VideoView.access$2100(VideoView.java:71)
12-19 11:20:12.567: D/MediaPlayer(1704): at android.widget.VideoView$7.surfaceCreated(VideoView.java:618)
12-19 11:20:12.567: D/MediaPlayer(1704): at android.view.SurfaceView.updateWindow(SurfaceView.java:602)
12-19 11:20:12.567: D/MediaPlayer(1704): at android.view.SurfaceView.access$000(SurfaceView.java:94)
12-19 11:20:12.567: D/MediaPlayer(1704): at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:183)
12-19 11:20:12.567: D/MediaPlayer(1704): at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:888)
12-19 11:20:12.567: D/MediaPlayer(1704): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2199)
12-19 11:20:12.567: D/MediaPlayer(1704): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1254)
12-19 11:20:12.567: D/MediaPlayer(1704): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6624)
12-19 11:20:12.567: D/MediaPlayer(1704): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:812)
12-19 11:20:12.567: D/MediaPlayer(1704): at android.view.Choreographer.doCallbacks(Choreographer.java:612)
12-19 11:20:12.567: D/MediaPlayer(1704): at android.view.Choreographer.doFrame(Choreographer.java:582)
12-19 11:20:12.567: D/MediaPlayer(1704): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:798)
12-19 11:20:12.567: D/MediaPlayer(1704): at android.os.Handler.handleCallback(Handler.java:733)
12-19 11:20:12.567: D/MediaPlayer(1704): at android.os.Handler.dispatchMessage(Handler.java:95)
12-19 11:20:12.567: D/MediaPlayer(1704): at android.os.Looper.loop(Looper.java:146)
12-19 11:20:12.567: D/MediaPlayer(1704): at android.app.ActivityThread.main(ActivityThread.java:5602)
12-19 11:20:12.567: D/MediaPlayer(1704): at java.lang.reflect.Method.invokeNative(Native Method)
12-19 11:20:12.567: D/MediaPlayer(1704): at java.lang.reflect.Method.invoke(Method.java:515)
12-19 11:20:12.567: D/MediaPlayer(1704): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
12-19 11:20:12.567: D/MediaPlayer(1704): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
12-19 11:20:12.567: D/MediaPlayer(1704): at dalvik.system.NativeStart.main(Native Method)
12-19 11:20:12.567: D/MediaPlayer(1704): Couldn't open file on client side, trying server side  

请帮助..

1 个答案:

答案 0 :(得分:1)

原生VideoView并不真正支持HLS流媒体。 使用ExoPlayer构建自定义视频播放器

在Android Developer Console中提到:

" ExoPlayer支持MediaPlayer当前未提供的功能,包括HTTP上的动态自适应流媒体(DASH),SmoothStreaming和通用加密。它的设计易于定制和扩展,允许使用自定义实现替换许多组件。由于ExoPlayer是您在应用程序中包含的库,因此可以轻松地与您的应用程序一起更新#34;

http://developer.android.com/guide/topics/media/exoplayer.html

此外,您还可以搜索ExoPlayer包装的库。

实施例。 :https://github.com/brianwernick/ExoMedia