Why do AVAudioPlayer continue playing after applcation comes from background mode, even if the player had been paused before开发者_Go百科 app went to background?
In common I wonder why AVAudioPlayer automatically continue playing after application comes from background (cause when app going to background - i can't catch as beginInterruption as other delegates of AVAudioPlayer and AVAudioSession). ps:sorry for my english:)
when you push the app in background the app becomes dormant i.e. it is no longer active. This is the reason that you are unable to catch beginInterruption. When the app is brought in foreground the app becomes active again, this is why AVAudioPlayer starts playing again..I hope this helps
I spend quite some hours today trying to figure out the exact same thing.
Whenever my application entered background mode, the audio would automatically pause itself after a UIApplicationDidEnterBackgroundNotification and continue playing before I got a UIApplicationWillEnterForegroundNoticiation. Even when I paused it when I received the background notification.
When I enabled the UIBackgroundMode audio, I was able to pause my AudioQueue (or AVAudioPlayer if you use that) myself when the application entered background. This resulted in my UI showing that the audio player was paused and enabled me to get full control over audio playback in between application states.
So far the fix I've come up with for iOS 13 SDK (not sure if this is relevant but the bug for me has started after migration from iOS 12 SDK to 13) is this as strange as it looks:
// duplicate pausing the player when app resigns active
self.audioPlayer.pause()
self.audioPlayer.pause()
精彩评论