IPhone: how to determine if iTunes is playing?

I noticed that some applications programmatically mute itunes (if it starts) at startup. How is this achieved? I have a game with background music and I would like to either stop itunes or at least get a message that itunes is playing so that I can stop background music.

THX, Mark.

+7
iphone audio itunes
source share
2 answers

You do not need. With the Audio Session, you can decide how the sound should behave.

From the Audio Programming Guide :

With the audio session interface, you specify aspects of your sound applications and set it to live harmoniously in the iPhone sound environment. You start by asking questions such as:

  • Do you want your sound to be muted by the Ring / Silent switch? The answer is probably yes if the sound does not matter to use your application successfully. (Users value the ability to run your game in a meeting with anyone wiser.)

  • Do you want iPod audio to continue playing when your sound starts? It can be a virtual piano, allowing users to play along with songs in their libraries. You want iPod audio to stop, however, for a streaming radio application.

You probably want:

UInt32 sessionCategory = kAudioSessionCategory_SoloAmbientSound; AudioSessionSetProperty ( kAudioSessionProperty_AudioCategory, sizeof (sessionCategory), &sessionCategory ); 

For more types of behavior, browse through the categories of audio messages or read the entire Audio Programming Guide .

+8
source share

I had the opposite problem. My application plays a short video without sound after launch. This made iTunes music play in the background to mute the sound.

To save music playback, I add this to applicationDidFinishLaunching:

 NSError* error; [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryAmbient error: &error]; if (error) NSLog(@"Unable to configure Audio"); 
0
source share

All Articles