如何使用 flutters video_player 或 chewie 或 video_viewer 插件播放 m3u8 链接?
How to play m3u8 links using flutters video_player or chewie or video_viewer plugin?
我注意到某些 link 无法通过使用 flutters video_player 插件在 iOS 设备上运行,但是如果我使用下面的示例 link,它在所有设备上运行良好,即使在 android 和 iOS.
上也是如此
https://sfux-ext.sfux.info/hls/chapter/105/1588724110/1588724110.m3u8
以下 link 无法在 iOS 设备上运行,但可在 android 设备上运行,
https://5421175365ea3.streamlock.net/live/smil:switch.smil/playlist.m3u8
https://dcunilive28-lh.akamaihd.net/i/dclive_1@533583/master.m3u8
知道我们如何让它发挥作用吗?
您的 HLS 播放列表非常糟糕并且有很多问题,最大的问题是缺少编解码器信息。
使用 Apples HTTP Livestreaming 工具验证您的播放列表。
第一个 link 的摘录:
Must Fix Issues
1. Measured peak bitrate compared to master playlist declared value exceeds error tolerance
Master Playlist Stream Definition for All Variants
2. I-frame playlists ( EXT-X-I-FRAME-STREAM-INF ) MUST be provided to support scrubbing and scanning UI
Master Playlist
3. Your EXT-X-STREAM-INF and EXT-X-I-FRAME-STREAM-INF tags MUST always provide CODECS attribute
Master Playlist Stream Definition for All Variants
4. Your EXT-X-STREAM-INF and EXT-X-I-FRAME-STREAM-INF tags MUST always provide the RESOLUTION attribute if the rendition(s) include video
Master Playlist Stream Definition for All Variants
5. You MUST include the AVERAGE-BANDWIDTH attribute
Master Playlist Stream Definition for All Variants
6. Each EXT-X-STREAM-INF tag MUST have a FRAME-RATE attribute
Master Playlist Stream Definition for All Variants
7. The server MUST deliver playlists using gzip content-encoding
All Variants
Master Playlist
8. The EXT-X-PROGRAM-DATE-TIME tag MUST be present in every live/linear media playlist
All Variants
9. You MUST provide at least 6 segments in a live/linear playlist
All Variants
10. If EXT-X-INDEPENDENT-SEGMENTS is not in master playlist, then you MUST use the EXT-X-INDEPENDENT-SEGMENTS tag in all video media playlists
All Variants
所有这些问题都会阻止 HLS 在 Apple 设备上播放,Android 可能会更宽松一些。
如果您使用 video_player,您应该为 ios
注释以下代码
// The player may be initialized but still needs to determine the duration.
if ([self duration] == 0) {
return;
}
第 315 行
YOUR_SDK_FOLDER\flutter\.pub-cache\hosted\pub.dartlang.org\video_player-your_player_version_no\Classes\FLTVideoPlayerPlugin.m
似乎实时 hls 流总是返回 duration=0
我注意到某些 link 无法通过使用 flutters video_player 插件在 iOS 设备上运行,但是如果我使用下面的示例 link,它在所有设备上运行良好,即使在 android 和 iOS.
上也是如此https://sfux-ext.sfux.info/hls/chapter/105/1588724110/1588724110.m3u8
以下 link 无法在 iOS 设备上运行,但可在 android 设备上运行,
https://5421175365ea3.streamlock.net/live/smil:switch.smil/playlist.m3u8
https://dcunilive28-lh.akamaihd.net/i/dclive_1@533583/master.m3u8
知道我们如何让它发挥作用吗?
您的 HLS 播放列表非常糟糕并且有很多问题,最大的问题是缺少编解码器信息。
使用 Apples HTTP Livestreaming 工具验证您的播放列表。
第一个 link 的摘录:
Must Fix Issues
1. Measured peak bitrate compared to master playlist declared value exceeds error tolerance
Master Playlist Stream Definition for All Variants
2. I-frame playlists ( EXT-X-I-FRAME-STREAM-INF ) MUST be provided to support scrubbing and scanning UI
Master Playlist
3. Your EXT-X-STREAM-INF and EXT-X-I-FRAME-STREAM-INF tags MUST always provide CODECS attribute
Master Playlist Stream Definition for All Variants
4. Your EXT-X-STREAM-INF and EXT-X-I-FRAME-STREAM-INF tags MUST always provide the RESOLUTION attribute if the rendition(s) include video
Master Playlist Stream Definition for All Variants
5. You MUST include the AVERAGE-BANDWIDTH attribute
Master Playlist Stream Definition for All Variants
6. Each EXT-X-STREAM-INF tag MUST have a FRAME-RATE attribute
Master Playlist Stream Definition for All Variants
7. The server MUST deliver playlists using gzip content-encoding
All Variants
Master Playlist
8. The EXT-X-PROGRAM-DATE-TIME tag MUST be present in every live/linear media playlist
All Variants
9. You MUST provide at least 6 segments in a live/linear playlist
All Variants
10. If EXT-X-INDEPENDENT-SEGMENTS is not in master playlist, then you MUST use the EXT-X-INDEPENDENT-SEGMENTS tag in all video media playlists
All Variants
所有这些问题都会阻止 HLS 在 Apple 设备上播放,Android 可能会更宽松一些。
如果您使用 video_player,您应该为 ios
注释以下代码// The player may be initialized but still needs to determine the duration.
if ([self duration] == 0) {
return;
}
第 315 行
YOUR_SDK_FOLDER\flutter\.pub-cache\hosted\pub.dartlang.org\video_player-your_player_version_no\Classes\FLTVideoPlayerPlugin.m
似乎实时 hls 流总是返回 duration=0