有没有办法用AVPlayer区分直播流和点播文件流?
我正在尝试为多种类型的流媒体创建一个更通用的媒体控制器,并希望使 UI 适应流的类型;
- 当它是点播文件流(即正在流式传输的单个 MP3 文件)时,您应该能够向前和向后搜索。因此,搜索滑块应该是可见的。
- 当它是直播时,不可能向前和向后搜索,因此应该隐藏搜索滑块。
有没有办法从 AVPlayer(或者可能是 AVPlayerItem 或 AVAsset)确定流的类型是什么?
I'm trying to create a more generic media controller for several types of streaming media and want to adapt the UI to the type of stream;
- When it's an on-demand file stream (i.e. a single MP3 file that's being streamed), you should be able to seek forward and backward. Thus, the seek slider should be visible.
- When it's a live stream, it isn't possible to seek forward and backward, and thus the seek slider should be hidden.
Is there any way to determine from the AVPlayer (or perhaps the AVPlayerItem or AVAsset) what the type of stream is?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
直播时长不定:
仅当
AVPlayerItem
项状态为AVPlayerItemStatusReadyToPlay
时才需要检查时长。The duration of live video is indefinite:
You have to check the duration only when the
AVPlayerItem
item status isAVPlayerItemStatusReadyToPlay
.对于那些仍在寻找此功能的人,
AVPlayerItem > AVPlayerItemAccessLogEvent > playbackType 属性可能会有所帮助。
我已经检查过“VOD”、“LIVE”类型是否已正确返回。
更多详细信息请参见此处
For those who are still looking for this feature,
AVPlayerItem > AVPlayerItemAccessLogEvent > playbackType property might be helpful.
I already checked "VOD", "LIVE" types were appropriately returned from it.
more detail in here
解决方案
您可以使用此代码轻松检测播放类型:
将观察者代码添加到您通常开始收听它们的位置。
不要忘记
另外,不要忘记在 deinit 中删除观察者;)
希望这会对某人有所帮助:)
Solution
You can use this code to easily detect the playback type:
Add the observer code to where you normally start to listen to them.
Don't Forget
Also, don't forget to remove the observer at the deinit ;)
Hope this will help someone :)
看来这是不可能的。
然而,人们可以检查直播的持续时间,该持续时间似乎始终高于 33000 秒。但是,该值仍然会波动,并且不希望对此进行检查,因为它可能会导致意外的行为。
It appears that this is not possible.
However, one could check the duration of a live stream, which seems to be consistently above 33000 seconds. However, this value still fluctuates and checking for this is undesirable, since it might cause unexpected behavior.
播放类型可以是直播、VOD 或文件。如果返回 nil,则播放类型未知。更多详细信息请参见此处
The playback type can be live, VOD, or from a file. If nil is returned the playback type is unknown. more detail in here