Allow playing iPod music in the background of SDL applications.
authorSam Lantinga <slouken@libsdl.org>
Thu, 01 Nov 2012 19:08:12 -0700
changeset 6628 7994e6979876
parent 6627 23b7cef164ae
child 6629 8e2c731103e6
Allow playing iPod music in the background of SDL applications. You can always change your audio session category afterwards if you want custom behavior.
src/audio/coreaudio/SDL_coreaudio.c
src/audio/coreaudio/SDL_coreaudio.h
--- a/src/audio/coreaudio/SDL_coreaudio.c	Thu Nov 01 00:12:57 2012 -0700
+++ b/src/audio/coreaudio/SDL_coreaudio.c	Thu Nov 01 19:08:12 2012 -0700
@@ -538,8 +538,16 @@
     impl->DetectDevices = COREAUDIO_DetectDevices;
 #else
     impl->OnlyHasDefaultOutputDevice = 1;
+
+    /* Set category to ambient sound so that other music continues playing.
+       You can change this at runtime in your own code if you need different
+       behavior.  If this is common, we can add an SDL hint for this.
+    */
+    AudioSessionInitialize(NULL, NULL, NULL, nil);
+    UInt32 category = kAudioSessionCategory_AmbientSound;
+    AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(UInt32), &category);
 #endif
-    
+
     impl->ProvidesOwnCallbackThread = 1;
 
     return 1;   /* this audio target is available. */
--- a/src/audio/coreaudio/SDL_coreaudio.h	Thu Nov 01 00:12:57 2012 -0700
+++ b/src/audio/coreaudio/SDL_coreaudio.h	Thu Nov 01 19:08:12 2012 -0700
@@ -35,6 +35,8 @@
 #if MAC_OS_X_VERSION_MAX_ALLOWED <= 1050
 #include <AudioUnit/AUNTComponent.h>
 #endif
+#else
+#include <AudioToolbox/AudioToolbox.h>
 #endif
 
 #include <AudioUnit/AudioUnit.h>