MPNowPlayingInfoCenter nowPlayingInfo ignored for AVPlayer audio via AirPlay

故事扮演 提交于 2019-12-04 17:38:05

问题


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?


回答1:


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.




回答2:


If you're on iOS7 you've got to disable external playback :

self.player.allowsExternalPlayback = NO;



来源:https://stackoverflow.com/questions/8808031/mpnowplayinginfocenter-nowplayinginfo-ignored-for-avplayer-audio-via-airplay

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!