diff options
author | Mikkel Krautz <mikkel@krautz.dk> | 2012-06-13 17:34:32 +0400 |
---|---|---|
committer | Mikkel Krautz <mikkel@krautz.dk> | 2012-06-13 17:34:32 +0400 |
commit | 91805ac204d4d805094822500b7208bf00aa8822 (patch) | |
tree | 2381eed9f213ebd17e6d29ced983a7f99b8879d1 /src/MKAudio.m | |
parent | e3fabadcc7768a7165130331c76265a763709cb6 (diff) |
MKAudio: make MixWithOthers work again, after Bluetooth support was added; alsoo be paranoid about MixWithOthers re-activation.
Diffstat (limited to 'src/MKAudio.m')
-rw-r--r-- | src/MKAudio.m | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/src/MKAudio.m b/src/MKAudio.m index 14857fb..98c7afd 100644 --- a/src/MKAudio.m +++ b/src/MKAudio.m @@ -24,6 +24,12 @@ static void MKAudio_InterruptCallback(void *udata, UInt32 interrupt) { if (interrupt == kAudioSessionBeginInterruption) { [audio stop]; } else if (interrupt == kAudioSessionEndInterruption) { + UInt32 val = TRUE; + OSStatus err = AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(val), &val); + if (err != kAudioSessionNoError) { + NSLog(@"MKAudio: unable to set MixWithOthers property in InterruptCallback."); + } + [audio start]; } } @@ -50,6 +56,12 @@ static void MKAudio_AudioInputAvailableCallback(MKAudio *audio, AudioSessionProp return; } } + + UInt32 val = TRUE; + OSStatus err = AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(val), &val); + if (err != kAudioSessionNoError) { + NSLog(@"MKAudio: unable to set MixWithOthers property in AudioInputAvailableCallback."); + } [audio restart]; } @@ -64,6 +76,12 @@ static void MKAudio_AudioRouteChangedCallback(MKAudio *audio, AudioSessionProper NSLog(@"MKAudio: audio route changed, skipping; reason=%i", reason); return; } + + UInt32 val = TRUE; + OSStatus err = AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(val), &val); + if (err != kAudioSessionNoError) { + NSLog(@"MKAudio: unable to set MixWithOthers property in AudioRouteChangedCallback."); + } NSLog(@"MKAudio: audio route changed, restarting audio; reason=%i", reason); [audio restart]; @@ -128,14 +146,6 @@ static void MKAudio_SetupAudioSession(MKAudio *audio) { } } - // Do we want to be mixed with other applications? - val = TRUE; - err = AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(val), &val); - if (err != kAudioSessionNoError) { - NSLog(@"MKAudio: unable to set MixWithOthers property."); - return; - } - // Set the preferred hardware sample rate. // // fixme(mkrautz): The AudioSession *can* reject this, in which case we need @@ -157,6 +167,16 @@ static void MKAudio_SetupAudioSession(MKAudio *audio) { return; } } + + // Allow us to be mixed with other applications. + // It's important that this call comes last, since changing the other OverrideCategory properties + // apparently reset the state of this property. + val = TRUE; + err = AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(val), &val); + if (err != kAudioSessionNoError) { + NSLog(@"MKAudio: unable to set MixWithOthers property."); + return; + } } #else static void MKAudio_SetupAudioSession(MKAudio *audio) { |