iPhone HTTP 视频流:如何在播放纯音频流时显示静止图像
我有一个 iPad 应用程序使用变体播放列表播放 http 视频流,该播放列表具有针对不同带宽具有不同比特率的多个流。其中之一是最低带宽的纯音频流。该应用程序使用AVPlayer来播放视频。由于某种原因,我无法使用 MPMoviePlayerViewController。
我遇到的问题是,当视频播放器播放纯音频流时,视频显示黑屏,但音频仍在播放。我认为这对用户来说很糟糕,他们不知道发生了什么。我想显示静态图像来代替视频播放器。像这样
有什么方法可以检测播放器何时切换到不同的流?或者检测流是否是纯音频?
I have an iPad app playing http video streaming using variant playlist, which have multi streams with different bit rate for different bandwidths. One of then is audio only stream for lowest bandwidth. The app use AVPlayer to play the video. For some reason, I can't use MPMoviePlayerViewController.
The problem I have is that when the video player play audio-only stream the video display black screen, the audio still playing. Which I think is awful to users, they don't know what going on. I want to display a still image in place of the video player. like this
Is there any way I can detect when the player switch to different stream? Or detect if the stream is audio-only?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
由于我遇到了这个问题并且之前的答案不完整(不涵盖直播案例) - 这是我的改进:
请注意 - 但这只会让您显示本地仅音频屏幕。
播放实时流时 - 仅音频的图稿应该来自流,因此我的代码更倾向于此:
添加观察代码:
删除观察代码:
hasVideoTracks 代码(在 AVPlayerItem 上的类别内):
注意:
Since I encountered this issue and the previous answer is not complete (doesn't cover live stream case) - here is my improvement on top of it:
Do note - this however will only let you show a local Audio only screen.
When playing a live stream - the Artwork for the audio only is supposed to come from the stream, so my code is more towards this:
Add observation code:
Remove observation code:
hasVideoTracks code (Inside a category over AVPlayerItem):
Note:
您可以为AVPlayerItem中的tracks属性设置观察者。
您需要实现每次更改曲目时都会调用的方法
还有一些调整空间,请查看 NSKeyValueObserving 协议 和 < a href="http://developer.apple.com/library/ios/#documentation/AVFoundation/Reference/AVPlayerItem_Class/Reference/Reference.html#//apple_ref/doc/c_ref/AVPlayerItem" rel="nofollow">AVPlayerItem
You can set up observer for the tracks property in AVPlayerItem.
Than you need to implement method that will be called every time when tracks will be changed
There some space for tuning up, take a look at NSKeyValueObserving Protocol and AVPlayerItem
掌握现代媒体播放 (WWDC 2014):
链接:https://developer.apple.com /videos/wwdc/2014/#503
Mastering Modern Media Playback (WWDC 2014):
Link: https://developer.apple.com/videos/wwdc/2014/#503