Android 3.x / HLS如何在流末尾启动

发布于 2025-01-04 10:00:13 字数 667 浏览 1 评论 0 原文

我正在使用以下代码播放 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谜兔 2025-01-11 10:00:13

我遇到了同样的问题 - 看起来当您在 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

抠脚大汉 2025-01-11 10:00:13

我不认为 HLS 规范没有明确说明从哪个段开始,但通常它从实时 hls 的倒数第三个段开始。

您所指的流是视频点播 (VOD) HLS 源。唯一的区别是播放列表使用#EXT-X-ENDLIST 终止。这会导致:

  • 刷新播放列表
  • 播放器没有从第一个块开始
$ curl http://iphoned5.akamai.com.edgesuite.net/mhbarron/nasatv/nasatv_700.m3u8
...
#EXTINF:10,
http://iphoned5.akamai.com.edgesuite.net/mhbarron/nasatv/nasatv_700/Seg_060110_103747_44/nasatv_700_060110_103747_87966.ts
#EXTINF:0,
http://iphoned5.akamai.com.edgesuite.net/mhbarron/nasatv/nasatv_700/Seg_060110_103747_44/nasatv_700_060110_103747_87967.ts
#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:

  • the player not refreshing the playlist
  • starting at the very first chunk.
$ curl http://iphoned5.akamai.com.edgesuite.net/mhbarron/nasatv/nasatv_700.m3u8
...
#EXTINF:10,
http://iphoned5.akamai.com.edgesuite.net/mhbarron/nasatv/nasatv_700/Seg_060110_103747_44/nasatv_700_060110_103747_87966.ts
#EXTINF:0,
http://iphoned5.akamai.com.edgesuite.net/mhbarron/nasatv/nasatv_700/Seg_060110_103747_44/nasatv_700_060110_103747_87967.ts
#EXT-X-ENDLIST

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文