2 Replies Latest reply: Jan 29, 2011 2:29 AM by RayNewbie
Den B. Level 1 Level 1 (5 points)
Hello:

I want to know if it's possible to tell if some outside app is currently playing music? (That outside app could most certainly be iPod, but also other apps, such as Pandora, for instance). I'm asking about a universal way to find out? (Hopefully there's one.)

MacBook Pro 17", 2.66 GHz i7, 4GB 1067 DDR3 RAM, OS X 10.6.4 /// iPhone 4, 32GB, iOS 4
  • 1. Re: Is it possible to detect if music is playing when my app starts?
    Den B. Level 1 Level 1 (5 points)
    I think I answered my own question

    UInt32 otherAudioIsPlaying;
    UInt32 propertySize = sizeof (otherAudioIsPlaying);

    AudioSessionGetProperty (
    kAudioSessionProperty_OtherAudioIsPlaying,
    &propertySize,
    &otherAudioIsPlaying
    );

    if (otherAudioIsPlaying) {
    [[AVAudioSession sharedInstance]
    setCategory: AVAudioSessionCategoryAmbient
    error: nil];
    } else {
    [[AVAudioSession sharedInstance]
    setCategory: AVAudioSessionCategorySoloAmbient
    error: nil];
    }

    and to mix with existing sounds:

    [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: nil];
    UInt32 allowMixing = true;
    OSStatus propertySetError = AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(allowMixing), &allowMixing);
  • 2. Re: Is it possible to detect if music is playing when my app starts?
    RayNewbie Level 5 Level 5 (6,810 points)
    Thanks for providing your solution, Den!! - Ray