orthehelper
orthehelper

Reputation: 4079

Application turns off playing music when launched

HI i have set my app audio session to ambientsound, when i launched the app for the fist time she just kill the music. i dont want this to happen. there is any other way to set this?

Upvotes: 0

Views: 937

Answers (1)

Oliver
Oliver

Reputation: 23510

Try this :

Activate audio session :

OSStatus activationResult = NULL;
result = AudioSessionSetActive (true);

Test if other audio is playing

UInt32 otherAudioIsPlaying;                                   // 1
UInt32 propertySize = sizeof (otherAudioIsPlaying);

AudioSessionGetProperty (                                     // 2
    kAudioSessionProperty_OtherAudioIsPlaying,
    &propertySize,
    &otherAudioIsPlaying
);

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

If YES, allow mixing

OSStatus propertySetError = 0;
UInt32 allowMixing = true;
propertySetError = AudioSessionSetProperty (
                       kAudioSessionProperty_OverrideCategoryMixWithOthers,  // 1
                       sizeof (allowMixing),                                 // 2
                       &allowMixing                                          // 3
                   );

Source : http://developer.apple.com/library/ios/#documentation/Audio/Conceptual/AudioSessionProgrammingGuide/Cookbook/Cookbook.html

Upvotes: 2

Related Questions