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?
If you just tap the play/pause button in the app the song is only paused, so to completely stop and exit music player tap the android menu button to open the menu for the music player then tap “End” at the bottom of the menu, or alternatively if you pull the notifications panel down from the top of your screen you will ...
Start by downloading the free YouCam Video app on your app store or Google Play. With a high 4.7 app rating and over 3,000 reviews, it is the best app to add music to videos for iPhone and Android in 2022.
Check out this question
Seems you can see if another audio is playing by checking the property kAudioSessionProperty_OtherAudioIsPlaying like this:
UInt32 propertySize, audioIsAlreadyPlaying=0;
propertySize = sizeof(UInt32);
AudioSessionGetProperty(kAudioSessionProperty_OtherAudioIsPlaying, &propertySize, &audioIsAlreadyPlaying);
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.
AudioSessionGetProperty
(as mentioned in jake_hetfield's answer) is deprecated as of iOS 7.
Instead, try this one-liner that uses isOtherAudioPlaying:
BOOL isOtherAudioPlaying = [[AVAudioSession sharedInstance] isOtherAudioPlaying];
Works on iOS 6+.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With