I currently have my game correctly handling disabling its own BGM when music is playing in the built-in iPod app, but it does not detect when an app such as Pandora is playing music.
Currently, in my applicationDidBecomeActive
method, I check [[MPMusicPlayerController iPodMusicPlayer] playbackState]
to determine whether music is playing. What is the equivalent of this to check if an app like Pandora is playing audio in the background?
As of iOS 8, the secondaryAudioShouldBeSilencedHint property should be used:
You may want to do something like this.....
1) Create A class to handle your audio settings say... "AudioManager"
2) Poll the Boolean "isOtherAudioPlaying"... maybe assign it to your own Boolean value.
AudioSessionGetProperty
(as mentioned in jake_hetfield's answer) is deprecated as of iOS 7.Instead, try this one-liner that uses isOtherAudioPlaying:
Works on iOS 6+.
Check out this question
Seems you can see if another audio is playing by checking the property kAudioSessionProperty_OtherAudioIsPlaying like this:
A complement to this could be to ask the user if he/she wants to have the game music or the already playing sound/music.