diff --git a/src/common/ios.h b/src/common/ios.h index 1b74a6a1e..1d93aa4b1 100644 --- a/src/common/ios.h +++ b/src/common/ios.h @@ -67,12 +67,12 @@ void vibrate(); /** * Enable mix mode (e.g. with background music apps) and playback with a muted device. **/ -void setAudioMixWithOthers(bool mixMode, bool playMuted); +void setAudioMixWithOthers(bool mixEnabled); /** * Returns whether another application is playing audio. **/ -bool audioShouldBeSilenced(); +bool hasBackgroundMusic(); } // ios } // love diff --git a/src/common/ios.mm b/src/common/ios.mm index e34d8f362..d7685873b 100644 --- a/src/common/ios.mm +++ b/src/common/ios.mm @@ -345,35 +345,26 @@ void vibrate() } } -void setAudioMixWithOthers(bool mixMode, bool playMuted) +void setAudioMixWithOthers(bool mixEnabled) { @autoreleasepool { - NSString *category = AVAudioSessionCategoryPlayback; - AVAudioSessionCategoryOptions options = 0; - NSError *err = nil; + NSString *category = AVAudioSessionCategorySoloAmbient; + NSError *err; - if (mixMode) - { - if (playMuted) - options = AVAudioSessionCategoryOptionMixWithOthers; - else - category = AVAudioSessionCategoryAmbient; - } - else if (!playMuted) - { - category = AVAudioSessionCategorySoloAmbient; - } + if (mixEnabled) + category = AVAudioSessionCategoryAmbient; - [[AVAudioSession sharedInstance] setCategory:category withOptions:options error:&err]; - if (err != nil) + if (![[AVAudioSession sharedInstance] setCategory:category error:&err]) NSLog(@"Error in AVAudioSession setCategory: %@", [err localizedDescription]); } } -bool audioShouldBeSilenced() +bool hasBackgroundMusic() { - return [[AVAudioSession sharedInstance] secondaryAudioShouldBeSilencedHint]; + if ([[AVAudioSession sharedInstance] respondsToSelector:@selector(secondaryAudioShouldBeSilencedHint)]) + return [[AVAudioSession sharedInstance] secondaryAudioShouldBeSilencedHint]; + return false; } } // ios diff --git a/src/modules/audio/wrap_Audio.cpp b/src/modules/audio/wrap_Audio.cpp index 2869b3adc..66e38f23d 100644 --- a/src/modules/audio/wrap_Audio.cpp +++ b/src/modules/audio/wrap_Audio.cpp @@ -299,7 +299,7 @@ int w_getDistanceModel(lua_State *L) #ifdef LOVE_IOS int w_setMixMode(lua_State *L) { - love::ios::setAudioMixWithOthers(lua_toboolean(L, 1), lua_toboolean(L, 2)); + love::ios::setAudioMixWithOthers(lua_toboolean(L, 1)); #else int w_setMixMode(lua_State *) { diff --git a/src/modules/system/System.cpp b/src/modules/system/System.cpp index 5951449f6..3d8ebd3fa 100644 --- a/src/modules/system/System.cpp +++ b/src/modules/system/System.cpp @@ -189,9 +189,9 @@ bool System::hasBackgroundMusic() const #if defined(LOVE_ANDROID) return love::android::hasBackgroundMusic(); #elif defined(LOVE_IOS) - return love::ios::audioShouldBeSilenced(); + return love::ios::hasBackgroundMusic(); #else - throw love::Exception("Unsupported platform."); + return false; #endif } diff --git a/src/modules/system/wrap_System.cpp b/src/modules/system/wrap_System.cpp index fd2cee7aa..925befba0 100644 --- a/src/modules/system/wrap_System.cpp +++ b/src/modules/system/wrap_System.cpp @@ -95,14 +95,7 @@ int w_vibrate(lua_State *L) int w_hasBackgroundMusic(lua_State *L) { - try - { - lua_pushboolean(L, instance()->hasBackgroundMusic()); - } - catch (love::Exception &) - { - lua_pushnil(L); - } + lua_pushboolean(L, instance()->hasBackgroundMusic()); return 1; } diff --git a/src/scripts/boot.lua b/src/scripts/boot.lua index 3c6676879..13ed3a891 100644 --- a/src/scripts/boot.lua +++ b/src/scripts/boot.lua @@ -374,8 +374,7 @@ function love.init() video = true, }, audio = { - mixmode = true, - playmuted = false, + mixwithsystem = true, -- Only relevant for Android / iOS. }, console = false, -- Only relevant for windows. identity = false, @@ -495,7 +494,7 @@ function love.init() end if love.audio then - love.audio.setMixMode(c.audio.mixmode, c.audio.playmuted) + love.audio.setMixMode(c.audio.mixwithsystem) end -- Our first timestep, because window creation can take some time diff --git a/src/scripts/boot.lua.h b/src/scripts/boot.lua.h index f6d4c8f67..4684661ab 100644 --- a/src/scripts/boot.lua.h +++ b/src/scripts/boot.lua.h @@ -683,9 +683,10 @@ const unsigned char boot_lua[] = 0x09, 0x09, 0x09, 0x76, 0x69, 0x64, 0x65, 0x6f, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, 0x2c, 0x0a, 0x09, 0x09, 0x7d, 0x2c, 0x0a, 0x09, 0x09, 0x61, 0x75, 0x64, 0x69, 0x6f, 0x20, 0x3d, 0x20, 0x7b, 0x0a, - 0x09, 0x09, 0x09, 0x6d, 0x69, 0x78, 0x6d, 0x6f, 0x64, 0x65, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, 0x2c, 0x0a, - 0x09, 0x09, 0x09, 0x70, 0x6c, 0x61, 0x79, 0x6d, 0x75, 0x74, 0x65, 0x64, 0x20, 0x3d, 0x20, 0x66, 0x61, 0x6c, - 0x73, 0x65, 0x2c, 0x0a, + 0x09, 0x09, 0x09, 0x6d, 0x69, 0x78, 0x77, 0x69, 0x74, 0x68, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x20, 0x3d, + 0x20, 0x74, 0x72, 0x75, 0x65, 0x2c, 0x20, 0x2d, 0x2d, 0x20, 0x4f, 0x6e, 0x6c, 0x79, 0x20, 0x72, 0x65, 0x6c, + 0x65, 0x76, 0x61, 0x6e, 0x74, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x41, 0x6e, 0x64, 0x72, 0x6f, 0x69, 0x64, 0x20, + 0x2f, 0x20, 0x69, 0x4f, 0x53, 0x2e, 0x0a, 0x09, 0x09, 0x7d, 0x2c, 0x0a, 0x09, 0x09, 0x63, 0x6f, 0x6e, 0x73, 0x6f, 0x6c, 0x65, 0x20, 0x3d, 0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x2c, 0x20, 0x2d, 0x2d, 0x20, 0x4f, 0x6e, 0x6c, 0x79, 0x20, 0x72, 0x65, 0x6c, 0x65, 0x76, 0x61, 0x6e, 0x74, 0x20, @@ -914,9 +915,8 @@ const unsigned char boot_lua[] = 0x09, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x61, 0x75, 0x64, 0x69, 0x6f, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a, 0x09, 0x09, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x61, 0x75, 0x64, 0x69, 0x6f, 0x2e, 0x73, 0x65, 0x74, 0x4d, 0x69, - 0x78, 0x4d, 0x6f, 0x64, 0x65, 0x28, 0x63, 0x2e, 0x61, 0x75, 0x64, 0x69, 0x6f, 0x2e, 0x6d, 0x69, 0x78, 0x6d, - 0x6f, 0x64, 0x65, 0x2c, 0x20, 0x63, 0x2e, 0x61, 0x75, 0x64, 0x69, 0x6f, 0x2e, 0x70, 0x6c, 0x61, 0x79, 0x6d, - 0x75, 0x74, 0x65, 0x64, 0x29, 0x0a, + 0x78, 0x4d, 0x6f, 0x64, 0x65, 0x28, 0x63, 0x2e, 0x61, 0x75, 0x64, 0x69, 0x6f, 0x2e, 0x6d, 0x69, 0x78, 0x77, + 0x69, 0x74, 0x68, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x29, 0x0a, 0x09, 0x65, 0x6e, 0x64, 0x0a, 0x09, 0x2d, 0x2d, 0x20, 0x4f, 0x75, 0x72, 0x20, 0x66, 0x69, 0x72, 0x73, 0x74, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x65, 0x70, 0x2c, 0x20, 0x62, 0x65, 0x63, 0x61, 0x75, 0x73, 0x65, 0x20, 0x77, 0x69, 0x6e, 0x64,