I found some weird UX, and when I went back and forth from the background and based on a bunch of messages, I planned to catch the handle a bit. I did something quite simple - check if other music is playing when the application comes to the fore:
func applicationWillEnterForeground(application: UIApplication) { if AVAudioSession.sharedInstance().otherAudioPlaying{ NSNotificationCenter.defaultCenter().postNotificationName(Notifications.ForegroundEnteredWithOtherAudioPlaying, object: nil) } }
If so, you can pause the player when you receive this notification. You mentioned that you didnβt work, but without seeing the rest of your code, itβs hard to understand why.
Another thing I had to do was remove the observer with the status flag from the player element, because I am listening to it for the ReadyToPlay value, where I tell AvPlayer to play. This works when the application comes to the forefront and there is an active audio session. Therefore, by removing this observer when paused and setting it every time I play (which is not crazy, because I claim that this restriction is OK, to say that I only watch after I got into the game), I can control a lot of weirdness.
I also wrote a bunch of test cases that I will cover here to make sure your experience is in very good shape. It is not comprehensive, but it is also quite thorough.
source share