I am building an app that uses the AVPlayer and is set up to operate with lock screen controls while the app is in the background. I have implemented the following appropriately:
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[[AVAudioSession sharedInstance] setActive: YES error: &error];
and I have MPNowPlayingInfoCenter
properly configured.
One bug I've encountered is that the lock screen's controls fail to work when I wish to resume playing after playing music from another app (for example, Spotify).
To reproduce this bug, I begin playing audio from my app, where setActive
is called when my AVPlayer plays. Then I switch to Spotify and play a song, where my audio dies down and pauses. After a few seconds, I switch back to my app and resume my audio. When I lock my device, and press buttons on my lock screen, I see my audio's information on the screen, but none of my controls are working like they should.
beginReceivingRemoteControlEvents
is called at startup within my appDelegate's applicationDidBecomeActive
I do have endReceivingRemoteControlEvents
in a dealloc method from my appDelegate (this is legacy code I've inherited), but that isn't called in this scenario.
EDIT: I forgot to note, I'm testing on an iPad running iOS11.4
EDIT 2: Sorry, I failed to mention that this worked fine before the update to iOS11.4
EDIT 3: I found the issue, it was a boolean flag buried in our legacy code that wasn't being reset