I\'m developing a music application, which should play music in the background.
I use the MPMoviePlayerController
to play the music. My code to initiate
The problem is that you are not satisfying the requirements to become master of the lock screen and control center, as I explain in my book. You should be seeing the modern (iOS 8) equivalent of this:
The fact that you are not seeing it suggests that you are omitting one or more of the requirements, which I list (quoting directly from my book here):
canBecomeFirstResponder
, and that responder must
actually be first responder.remoteControlReceivedWithEvent:
. beginReceivingRemoteControlEvents
.I don't know which of those you are omitting; it could be more than one. You might like to compare your code with a working example, here:
https://github.com/mattneub/Programming-iOS-Book-Examples/blob/master/iOS7bookExamples/bk2ch14p653backgroundPlayerAndInterrupter/backgroundPlayer/backgroundPlayer/ViewController.m
Expanding further on @matt's answer, it's required that you call endReceivingRemoteControlEvents
and resignFirstResponder
when the app comes back into the foreground (applicationDidBecomeActive
). Otherwise the OS assumes you are a bad actor (or forgot to turn them off) and turns off your ability to show the sleep controls entirely, even after you call beginReceivingRemoteControlEvents
again. I added these calls and now the Sleep Controls always show when they should.
Want to expand @matt's answer - setting nowPlayingInfo is useless when you use AVAudioSessionCategoryOptionMixWithOthers
option.
Want to explain @zakhej's answer - what's happens when set AVAudioSessionCategoryOptionMixWithOthers.
so. when you set category AVAudioSessionCategoryAmbient, AVAudioSessionCategoryPlayAndRecord and mix with others, AVAudioSessionCategoryPlayback and mix with others, setting MPNowPlayingInfoCenter's nowPlayingInfo is useless.