MPMoviePlayerController background audio issue in iOS5

旧城冷巷雨未停 提交于 2019-12-03 15:03:56

Finally figured out the issue. This is solved in this post in apple dev forums (needs login to see). That post was applicable to AVPlayer but also fixes the problem with MPMoviePlayerController as well.

Basically, this is an excerpt from that post:

your app must support remote control events! These are the audio controller interface prex/nex/play/pause on the left of the multitask switcher taskbar (not sure about the proper name of the thing). You to this ensuring your view becomes First Controller and then calling

> [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

in viewDidLoad. Once you do this, your Player will no longer return NO!!

My situation was different and I'm only answering here (and in the other SO question) to help future searchers on this error message. This does not answer the original question.

My app plays a sound OR a song but when I first coded it could play both. And in testing I always tested with a song. I played the song in the usual way:

    self.musicQuery = [MPMediaQuery songsQuery];
    [_musicQuery addFilterPredicate:[MPMediaPropertyPredicate predicateWithValue:selectedSongID forProperty:MPMediaItemPropertyPersistentID comparisonType:MPMediaPredicateComparisonEqualTo]];
    [_musicQuery setGroupingType:MPMediaGroupingTitle];
    [_myPlayer setQueueWithQuery:_musicQuery];

    [_myPlayer play];

Weeks passed and I started testing with the sound, played with AVAudioPlayer. My app started freezing for 5 seconds and I'd get the MediaPlayer: Message playbackState timed out message in the Console.

It turns out that passing a query that was empty was causing the freeze and the message. Changing my app's logic to only play a song when there was a song to play fixed it.

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