Ad banners causing MPNowPlayingInfoCenter to lose state

Viewed 324

I have an app which plays audio using AVPlayer and I touch the right APIs to get the Now Playing info to update in Control Center.

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:0 error:&categoryError];
[[AVAudioSession sharedInstance] setMode:AVAudioSessionModeSpokenAudio error:&modeError];
[[AVAudioSession sharedInstance] setActive:YES error:&activeError];

[MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = {...};
...
MPRemoteCommandCenter * const commandCenter = [MPRemoteCommandCenter sharedCommandCenter];
commandCenter.playCommand.enabled = YES;
...

This API works as expected, until some ads appear using Google's AdMob framework. These are the standard MREC and banners which are presented in UIWebView instances. As soon as one appears, the Now Playing state reverts back to the Music app, and the ability to use the remote controls disappears.

Once this happens, I can't even re-set the Now Playing info, it's like it's stuck. Although, when I print out the value of [[MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo, it is as I expect, it just doesn't show.

The ads play no audio or video, but somehow they are corrupting the Now Playing API and it does not recover.

I've reached out to Google and Apple as to how to fix this, but in the meantime wondered if anyone had any workarounds to suggest?

1 Answers

I found this question when looking into a similar issue with the Google Interactive Media Ads SDK (IMA SDK) where it was automatically changing the Now Playing state to just say "Advertisement". Ultimately found the flag on the IMAAdsSettings object, disablesNowPlayingInfo Documentation. Setting this to true resolved my issue.

        let adsLoaderSettings = IMASettings()
        adsLoaderSettings.disableNowPlayingInfo = true
        adsLoader = IMAAdsLoader(settings: adsLoaderSettings)
Related