The code related to t.audio.mixwithsystem=true is run before the audio module is loaded. Fixes issue #1430.

This commit is contained in:
Alex Szpakowski
2018-12-26 11:36:23 -04:00
parent f504ace6cd
commit 324a290040
8 changed files with 43 additions and 17 deletions
+1 -1
View File
@@ -71,7 +71,7 @@ void vibrate();
/**
* Enable mix mode (e.g. with background music apps) and playback with a muted device.
**/
void setAudioMixWithOthers(bool mixEnabled);
bool setAudioMixWithOthers(bool mixEnabled);
/**
* Returns whether another application is playing audio.
+5 -2
View File
@@ -347,7 +347,7 @@ void vibrate()
}
}
void setAudioMixWithOthers(bool mixEnabled)
bool setAudioMixWithOthers(bool mixEnabled)
{
@autoreleasepool
{
@@ -357,8 +357,11 @@ void setAudioMixWithOthers(bool mixEnabled)
if (mixEnabled)
category = AVAudioSessionCategoryAmbient;
if (![[AVAudioSession sharedInstance] setCategory:category error:&err])
bool success = [[AVAudioSession sharedInstance] setCategory:category error:&err];
if (!success)
NSLog(@"Error in AVAudioSession setCategory: %@", [err localizedDescription]);
return success;
}
}
+1 -2
View File
@@ -33,8 +33,7 @@ namespace audio
bool Audio::setMixWithSystem(bool mix)
{
#ifdef LOVE_IOS
love::ios::setAudioMixWithOthers(mix);
return true;
return love::ios::setAudioMixWithOthers(mix);
#else
LOVE_UNUSED(mix);
return false;
+1 -1
View File
@@ -261,7 +261,7 @@ public:
* Sets whether audio from other apps mixes with love.audio or is muted,
* on supported platforms.
**/
bool setMixWithSystem(bool mix);
static bool setMixWithSystem(bool mix);
private:
+1 -1
View File
@@ -526,7 +526,7 @@ int w_isEffectsSupported(lua_State *L)
int w_setMixWithSystem(lua_State *L)
{
luax_pushboolean(L, instance()->setMixWithSystem(luax_checkboolean(L, 1)));
luax_pushboolean(L, Audio::setMixWithSystem(luax_checkboolean(L, 1)));
return 1;
}
+23
View File
@@ -69,6 +69,11 @@ extern "C"
# include "graphics/Graphics.h"
#endif
// For love::audio::Audio::setMixWithSystem.
#ifdef LOVE_ENABLE_AUDIO
# include "audio/Audio.h"
#endif
// Scripts
#include "scripts/nogame.lua.h"
#include "scripts/boot.lua.h"
@@ -305,6 +310,19 @@ static int w__setGammaCorrect(lua_State *L)
return 0;
}
static int w__setAudioMixWithSystem(lua_State *L)
{
bool success = false;
#ifdef LOVE_ENABLE_AUDIO
bool mix = love::luax_checkboolean(L, 1);
success = love::audio::Audio::setMixWithSystem(mix);
#endif
love::luax_pushboolean(L, success);
return 1;
}
static int w_love_setDeprecationOutput(lua_State *L)
{
bool enable = love::luax_checkboolean(L, 1);
@@ -362,6 +380,11 @@ int luaopen_love(lua_State *L)
lua_pushcfunction(L, w__setGammaCorrect);
lua_setfield(L, -2, "_setGammaCorrect");
// Exposed here because we need to be able to call it before the audio
// module is initialized.
lua_pushcfunction(L, w__setAudioMixWithSystem);
lua_setfield(L, -2, "_setAudioMixWithSystem");
lua_newtable(L);
for (int i = 0; love::VERSION_COMPATIBILITY[i] != nullptr; i++)
+4 -4
View File
@@ -468,6 +468,10 @@ function love.init()
love._setGammaCorrect(c.gammacorrect)
end
if love._setAudioMixWithSystem and c.audio then
love._setAudioMixWithSystem(c.audio.mixwithsystem)
end
-- Gets desired modules.
for k,v in ipairs{
"data",
@@ -545,10 +549,6 @@ function love.init()
end
end
if love.audio then
love.audio.setMixWithSystem(c.audio.mixwithsystem)
end
-- Our first timestep, because window creation can take some time
if love.timer then
love.timer.step()
+7 -6
View File
@@ -867,6 +867,13 @@ const unsigned char boot_lua[] =
0x72, 0x72, 0x65, 0x63, 0x74, 0x28, 0x63, 0x2e, 0x67, 0x61, 0x6d, 0x6d, 0x61, 0x63, 0x6f, 0x72, 0x72, 0x65,
0x63, 0x74, 0x29, 0x0a,
0x09, 0x65, 0x6e, 0x64, 0x0a,
0x09, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x5f, 0x73, 0x65, 0x74, 0x41, 0x75, 0x64, 0x69, 0x6f,
0x4d, 0x69, 0x78, 0x57, 0x69, 0x74, 0x68, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x20, 0x61, 0x6e, 0x64, 0x20,
0x63, 0x2e, 0x61, 0x75, 0x64, 0x69, 0x6f, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
0x09, 0x09, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x5f, 0x73, 0x65, 0x74, 0x41, 0x75, 0x64, 0x69, 0x6f, 0x4d, 0x69,
0x78, 0x57, 0x69, 0x74, 0x68, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 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, 0x47, 0x65, 0x74, 0x73, 0x20, 0x64, 0x65, 0x73, 0x69, 0x72, 0x65, 0x64, 0x20, 0x6d,
0x6f, 0x64, 0x75, 0x6c, 0x65, 0x73, 0x2e, 0x0a,
0x09, 0x66, 0x6f, 0x72, 0x20, 0x6b, 0x2c, 0x76, 0x20, 0x69, 0x6e, 0x20, 0x69, 0x70, 0x61, 0x69, 0x72, 0x73,
@@ -1002,12 +1009,6 @@ const unsigned char boot_lua[] =
0x77, 0x2e, 0x69, 0x63, 0x6f, 0x6e, 0x29, 0x29, 0x0a,
0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a,
0x09, 0x65, 0x6e, 0x64, 0x0a,
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, 0x57, 0x69, 0x74, 0x68, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 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,
0x6f, 0x77, 0x20, 0x63, 0x72, 0x65, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x61, 0x6e, 0x20, 0x74, 0x61,