【问题标题】:Playing .m3u8 file through HTTPS on android 2.3在 android 2.3 上通过 HTTPS 播放 .m3u8 文件
【发布时间】:2023-03-21 09:04:01
【问题描述】:

在我的代码中的某个时刻,应用程序找到了一个指向 .m3u8 文件的 URL。这就是接下来会发生的事情:

mVideoView.setVideoURI(Uri.parse(feed.getUrl().toString())); // feed.getUrl returns the url
mVideoView.start();

它在 Android 3.1+ 上运行良好。不在早期版本上,因为它使用 https(参见:http://developer.android.com/guide/appendix/media-formats.html

所以我所做的是我为 Android 2.2+ 创建了一个新版本的应用程序,它使用了 vitamio ,这是一个应该让我更轻松的库。然而,在 (android.widget.VideoView) 完美处理的地方,(io.vov.vitamio.widget.VideoView) 需要很长时间来加载流并最终在崩溃时说:

但是,当我尝试加载此 URL 时:http://devimages.apple.com/iphone/samples/bipbop/gear1/prog_index.m3u8 效果很好!

我无法分享我需要使用的 URL,但这是它指向的 .m3u8 的内容:

#EXTM3U
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=264000
playlist.m3u8?session=003016302664236&index=0
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1364000
playlist.m3u8?session=003016302664236&index=1
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=44000
playlist.m3u8?session=003016302664236&index=2

所以我可以看到这个和 Apple 示例之间的主要区别是我使用 https,我的文件指向其他 .m3u8 文件(而 Apple 的 .m3u8 指向 .ts 文件).. 两者似乎都使用 AAC 音频。

问题似乎与维生素有关。我怎样才能绕过这个崩溃?非常感谢。

【问题讨论】:

    标签: android video https m3u8


    【解决方案1】:

    我找到了解决办法!

    所以我应该说的第一件事是我很困惑,我没有使用 HTTPS,但我的解决方案也应该适用于 https。

    首先,您可能需要像我一样使用 Vitamio,因为 Gingerbread 不支持直播(再次阅读this)。现在的问题是,如果您的 M3u8 文件是 .ts 文件列表,它应该可以正常工作。但如果它指向其他 m3u8 文件..

    好吧,您将不得不自己解析它。例如,您可以这样做:

    url = new URL(livetvchannel.getUrl());
    InputStream M3U8 = (InputStream) url.getContent();      
    BufferedReader br = new BufferedReader(new InputStreamReader(M3U8));
    for(int i = 0; i < 2; ++i)
        br.readLine();
    String target = br.readLine(); //this parses the third line of the playlist
    br.close();
    url = new URL(baseURL.concat(target)); 
    //if the m3u8 url is relative, you have to concat it with the path
    //Note: You have to do all this in a thread, you can't do network on UiThread
    
    
    mVideoView.setVideoURI(Uri.parse(url.toString())); //Run this on UiThread
    

    url 将指向视频流。你去吧!最后也没那么难。 :)

    【讨论】:

    • 但是在解析之后你将如何找出你设备的带宽呢?因为根据带宽你必须选择合适的m3u8链接。这才是自适应码率的正确方式。
    猜你喜欢
    • 2015-10-03
    • 2014-04-04
    • 2016-03-08
    • 1970-01-01
    • 1970-01-01
    • 2023-03-21
    • 1970-01-01
    • 2023-03-17
    • 2014-02-12
    相关资源
    最近更新 更多