views:

34

answers:

1

I am making a game for iphone/ipad, and don't want my background music to interfere with music the user might already be playing.

I know I can get the state of the iPod app using MPPlayerController, but how would my app figure out if something else, like Pandora, was playing background audio on iOS4?

+3  A: 

I finally figured this out. I had seen plenty of examples, but couldn't ever get them to work.

Most of the examples out there don't point out that for something like:

    UInt32   propertySize, audioIsAlreadyPlaying;

propertySize = sizeof(UInt32);
AudioSessionGetProperty(kAudioSessionProperty_OtherAudioIsPlaying, &propertySize, &audioIsAlreadyPlaying);

to work, the proper framework to add to you app is AudioToolbox. I kept trying to add other audio frameworks and always missed that one.

Once you add that frame work (and import it into the code file in question) just test to see if audioIsAlreadyPlaying is zero or one.

gotung
Note that you have to have initialised your audio session before making this call or you will potentially get a false negative. This is a common gotcha (or at least I've seen many a person on forums or in conversations that had this problem)
Laughing_Jack