本文介绍了通过HTTPS在Android 2.3播放.m3u8文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前在我的code某些时候,应用程序发现一个指向.m3u8文件的URL。这是接下来会发生什么:

At some point in my code, the app finds an URL that points to a .m3u8 file. This is what happens next :

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

和它工作正常在Android 3.1+。未在早期版本,因为它使用HTTPS(见: http://developer.android .COM /引导/附件/媒体formats.html

And it works FINE on Android 3.1+. Not on earlier versions because it uses https (see this : http://developer.android.com/guide/appendix/media-formats.html )

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

So what I did is I created a new version of my app for Android 2.2+ that uses vitamio , a library that's supposed to make it easier for me. However, where (android.widget.VideoView) handled it perfectly, (io.vov.vitamio.widget.VideoView) takes a very long time to load the stream and ends up saying this while crashing :

但是,当我尝试加载该URL:的http:// devimages.apple.com/iphone/samples/bipbop/gear1/prog_index.m3u8 它工作正常!

BUT, when I try to load this URL : http://devimages.apple.com/iphone/samples/bipbop/gear1/prog_index.m3u8It works fine !

我不能分享我需要使用的网址,但这里的它是指向.m3u8的内容:

I can't share the URL I need to use, but here's the contents of the .m3u8 it is pointing to:

#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

所以,主要的区别我可以这个和苹果的样本之一之间看,是我使用HTTPS,我的文件是指向其他.m3u8文件(而苹果的.m3u8指向.TS文件)..似乎都使用AAC音频。

So the main differences I can see between this one and the Apple sample one, is I'm using https, my file is pointing to other .m3u8 files (while Apple's .m3u8 is pointing to .ts files)..Both seem to use AAC audio.

这个问题似乎是与vitamio。我怎样才能解决这个崩溃得到什么呢?非常感谢你。

The problem seems to be related to vitamio. How can I get around this crash ? Thank you very much.

推荐答案

我找到了解决方法!

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

So the first thing I should say is that I was confused, and I wasn't using HTTPS, but my solution should work for https too.

首先,你可能需要使用Vitamio像我这样做,是因为姜饼不支持流媒体直播(再次,读的)。现在的事情是,如果您的M3U8文件是.TS文件列表,它应该工作的罚款。但是,如果它是指向其他M3U8文件。

First, you probably need to use Vitamio like I did, because Gingerbread does not support live streaming (again, read this). Now the thing is that if your M3u8 file is a list of .ts files, it should work fine. But if it's pointing to other m3u8 files..

那么你得自己解析它。你可以做到这一点,例如是这样的:

Well you're gonna have to parse it yourself. You can do it this way for example :

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将指向视频流。而且你去那里!到底是不是很辛苦。 :)

url will point to the video stream. And there you go ! Wasn't that hard in the end. :)

这篇关于通过HTTPS在Android 2.3播放.m3u8文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-11 13:06