MPNowPlayingInfoCenter nowPlayingInfo 通过 AirPlay 忽略 AVPlayer 音频
我已经使用 AVPlayer 实现了音频播放,播放远程 mp3 url。
我想使用 MPNowPlayingInfoCenter
nowPlayingInfo
方法显示有关当前播放音频的信息。
当我锁定屏幕时,我确实看到了我设置的图像和标题,所以我知道这个方法正在以某种方式注册信息,但是当我切换到 AirPlay 到 AppleTV 时,显示看起来像通用视频输出,带有底部的进度条,但正确显示了经过的时间和持续时间。
如果我设置了相同的 nowPlayingInfo
,但随后使用 AudioQueue 启动一些音频,那么它会在一半屏幕上正确显示图像(看起来就像使用 iPod/音乐应用程序播放播客一样)。
这是否只是使用 AVPlayer 对音频的 AirPlay 支持的限制,或者是否有某种方法可以让它正确显示图像和信息?
I have implemented audio playback using AVPlayer, playing a remote mp3 url.
I want to display the information about the currently playing audio using the MPNowPlayingInfoCenter
nowPlayingInfo
method.
When I lock the screen, I do see the image and title I set, so I know that this method is registering the information in some way, but when I switch to AirPlay to an AppleTV, the display looks like a generic video output, with the progress bar at bottom, but elapsed time and duration correctly displayed.
If I set this same nowPlayingInfo
, but then start some audio using an AudioQueue, then it properly displays the image on half the screen (it looks just like playing a podcast with the iPod/Music app).
Is this just a limitation of AirPlay support for audio using AVPlayer, or is there some way to get it to display the image and info properly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的 - 我浏览了苹果开发论坛并找到了提示。
如果您仅将 AVPlayer 用于音频,并希望它在播放时在后台工作,则需要禁用
allowsAirPlayVideo
设置。显然,iOS 5+ 上的 AVPlayer 假定它正在通过 AirPlay 播放视频,因此不允许后台播放,除非您明确禁用视频 AirPlay。
一旦禁用此功能(即
self.player.allowsAirPlayVideo = NO;
),您的音频仍将通过 AirPlay 播放,但现在它将正确显示音频/iPod 之类的界面。Ok - I dug through the apple dev forums and found a hint.
If you are using AVPlayer for audio only, and want it to work in the background while doing airplay, you need to disable the
allowsAirPlayVideo
setting.Apparently AVPlayer on iOS 5+ assumes that it is playing back video via AirPlay, and so does not allow backgrounding, unless you explicitly disable video AirPlay.
Once you disable this (i.e.
self.player.allowsAirPlayVideo = NO;
) then your audio will still play via AirPlay, but now it will now show the audio/ipod like interface correctly.如果您使用的是 iOS7,则必须禁用外部播放:
self.player.allowsExternalPlayback = NO;
If you're on iOS7 you've got to disable external playback :
self.player.allowsExternalPlayback = NO;