Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS: How do I detect if music is playing in any background music app?

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?

like image 839
Tim R. Avatar asked Sep 18 '12 11:09

Tim R.


People also ask

How can I stop the music playing 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 ...

What music apps use background?

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.


2 Answers

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.

like image 39
jake_hetfield Avatar answered Oct 25 '22 10:10

jake_hetfield


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+.

like image 146
Jon Schneider Avatar answered Oct 25 '22 12:10

Jon Schneider