I am playing HTML video from WKWebView while Spotify is running on background. As soon as the audio of the video starts, Spotify's audio fade out (as expected).
Once the video ends, Spotify not resume. Actually, it looks like Apple Music is now focused in MPNowPlayingInfoCenter (a bit similar to this issue).
I was trying to workaround it by doing the following when the video ended:
[AVAudioSession sharedInstance] setActive:YES
and then:
[AVAudioSession sharedInstance] setActive:NO withOptions: AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation
just to trigger Spotify back. Didn't work. No matter what I do, it looks like WKWebView is somehow killing Spotify's listener or resets the audio session, once the HTML audio plays.
I know WKWebView is working on a different process and ignoring the AudioSession categories/activation. But do someone have an assumption of why it actually rests the background music to a state it doesn't recover?
I tried many variations of AVAudioSession API but nothing helped.
It is also worth mentioning that as long as the audio is muted - everything works fine. But that's not a good option.