我正在使用以下代码播放 HLS 流:
mediaPlayer = new MediaPlayer();
mediaPlayer.setDataSource("http://iphoned5.akamai.com.edgesuite.net/mhbarron/nasatv/nasatv_all.m3u8");
mediaPlayer.setDisplay(holder);
mediaPlayer.setOnBufferingUpdateListener(this);
mediaPlayer.setOnCompletionListener(this);
mediaPlayer.setOnPreparedListener(this);
mediaPlayer.setOnVideoSizeChangedListener(this);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.prepareAsync();
使用此代码,根据在 VLC 中播放的相同流,我在视频中看到的内容晚了大约 5 分钟。
播放器开始播放 .m3u8 文件的第一个块。
但 hls 规范明确指出第一个块是较旧的,最后一个块是最新的。因此播放器应该开始播放文件的最后一个块。
我怀疑与 setDataSource 方法的参数有关,但我不知道如何做。
I am playing an HLS stream with the following code :
mediaPlayer = new MediaPlayer();
mediaPlayer.setDataSource("http://iphoned5.akamai.com.edgesuite.net/mhbarron/nasatv/nasatv_all.m3u8");
mediaPlayer.setDisplay(holder);
mediaPlayer.setOnBufferingUpdateListener(this);
mediaPlayer.setOnCompletionListener(this);
mediaPlayer.setOnPreparedListener(this);
mediaPlayer.setOnVideoSizeChangedListener(this);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.prepareAsync();
With this code, what I see in the video is about 5 minutes late according to the same stream played into VLC.
The player is starting to play the first chunk of the .m3u8 file.
But the hls specification precises that the first chunk are the older and the last the newest. So the player should start to play the last chunk of the file.
I suspect there is something to do with the parameters of the setDataSource method but I cannot figure how.
发布评论
评论(2)
我遇到了同样的问题 - 看起来当您在 Android 上启动实时 HLS feed(没有 EXT-X-ENDLIST 标签)时,核心 HLS 解析组件中存在一个错误,无法在实时点启动(提要结束),而是从流的开头开始。
code.google.com 上有一个关于此问题的错误 - 您可以在那里“加星标”或对其进行投票:
http://code.google.com/p/android/issues/detail?id=37156
I encountered the same issue - it looks like when you start a live HLS feed (that does NOT have the EXT-X-ENDLIST tag) on Android, there is a bug in the core HLS parsing components that fails to start at the live point (end of the feed), and instead starts at the beginning of the stream.
There is a bug filed on code.google.com about this - you can 'star' or upvote it there:
http://code.google.com/p/android/issues/detail?id=37156
我不认为 HLS 规范没有明确说明从哪个段开始,但通常它从实时 hls 的倒数第三个段开始。
您所指的流是视频点播 (VOD) HLS 源。唯一的区别是播放列表使用#EXT-X-ENDLIST 终止。这会导致:
。看看 Envivio 页面,我相信他们有一些可以测试的实时 HLS 频道。
一般性评论:在测试 HLS 时不要依赖 VLC。
I don't believe the HLS specification does not explicitly state which segment to start with for, but usually it starts on the third last segment for live hls.
The stream you are referring to is a Video on Demand (VOD) HLS source. The only difference is that the playlist is terminated using a #EXT-X-ENDLIST. Which causes:
Have a look at at the Envivio page I believe they have some live HLS channels you can test with.
A general comment: don't rely on VLC when it comes to testing HLS.