mirror of
https://github.com/love2d/love.git
synced 2026-08-17 19:23:38 +02:00
The code related to t.audio.mixwithsystem=true is run before the audio module is loaded. Fixes issue #1430.
This commit is contained in:
+1
-1
@@ -71,7 +71,7 @@ void vibrate();
|
|||||||
/**
|
/**
|
||||||
* Enable mix mode (e.g. with background music apps) and playback with a muted device.
|
* 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.
|
* Returns whether another application is playing audio.
|
||||||
|
|||||||
+5
-2
@@ -347,7 +347,7 @@ void vibrate()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setAudioMixWithOthers(bool mixEnabled)
|
bool setAudioMixWithOthers(bool mixEnabled)
|
||||||
{
|
{
|
||||||
@autoreleasepool
|
@autoreleasepool
|
||||||
{
|
{
|
||||||
@@ -357,8 +357,11 @@ void setAudioMixWithOthers(bool mixEnabled)
|
|||||||
if (mixEnabled)
|
if (mixEnabled)
|
||||||
category = AVAudioSessionCategoryAmbient;
|
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]);
|
NSLog(@"Error in AVAudioSession setCategory: %@", [err localizedDescription]);
|
||||||
|
|
||||||
|
return success;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,8 +33,7 @@ namespace audio
|
|||||||
bool Audio::setMixWithSystem(bool mix)
|
bool Audio::setMixWithSystem(bool mix)
|
||||||
{
|
{
|
||||||
#ifdef LOVE_IOS
|
#ifdef LOVE_IOS
|
||||||
love::ios::setAudioMixWithOthers(mix);
|
return love::ios::setAudioMixWithOthers(mix);
|
||||||
return true;
|
|
||||||
#else
|
#else
|
||||||
LOVE_UNUSED(mix);
|
LOVE_UNUSED(mix);
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -261,7 +261,7 @@ public:
|
|||||||
* Sets whether audio from other apps mixes with love.audio or is muted,
|
* Sets whether audio from other apps mixes with love.audio or is muted,
|
||||||
* on supported platforms.
|
* on supported platforms.
|
||||||
**/
|
**/
|
||||||
bool setMixWithSystem(bool mix);
|
static bool setMixWithSystem(bool mix);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|||||||
@@ -526,7 +526,7 @@ int w_isEffectsSupported(lua_State *L)
|
|||||||
|
|
||||||
int w_setMixWithSystem(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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -69,6 +69,11 @@ extern "C"
|
|||||||
# include "graphics/Graphics.h"
|
# include "graphics/Graphics.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// For love::audio::Audio::setMixWithSystem.
|
||||||
|
#ifdef LOVE_ENABLE_AUDIO
|
||||||
|
# include "audio/Audio.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
// Scripts
|
// Scripts
|
||||||
#include "scripts/nogame.lua.h"
|
#include "scripts/nogame.lua.h"
|
||||||
#include "scripts/boot.lua.h"
|
#include "scripts/boot.lua.h"
|
||||||
@@ -305,6 +310,19 @@ static int w__setGammaCorrect(lua_State *L)
|
|||||||
return 0;
|
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)
|
static int w_love_setDeprecationOutput(lua_State *L)
|
||||||
{
|
{
|
||||||
bool enable = love::luax_checkboolean(L, 1);
|
bool enable = love::luax_checkboolean(L, 1);
|
||||||
@@ -362,6 +380,11 @@ int luaopen_love(lua_State *L)
|
|||||||
lua_pushcfunction(L, w__setGammaCorrect);
|
lua_pushcfunction(L, w__setGammaCorrect);
|
||||||
lua_setfield(L, -2, "_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);
|
lua_newtable(L);
|
||||||
|
|
||||||
for (int i = 0; love::VERSION_COMPATIBILITY[i] != nullptr; i++)
|
for (int i = 0; love::VERSION_COMPATIBILITY[i] != nullptr; i++)
|
||||||
|
|||||||
@@ -468,6 +468,10 @@ function love.init()
|
|||||||
love._setGammaCorrect(c.gammacorrect)
|
love._setGammaCorrect(c.gammacorrect)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if love._setAudioMixWithSystem and c.audio then
|
||||||
|
love._setAudioMixWithSystem(c.audio.mixwithsystem)
|
||||||
|
end
|
||||||
|
|
||||||
-- Gets desired modules.
|
-- Gets desired modules.
|
||||||
for k,v in ipairs{
|
for k,v in ipairs{
|
||||||
"data",
|
"data",
|
||||||
@@ -545,10 +549,6 @@ function love.init()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if love.audio then
|
|
||||||
love.audio.setMixWithSystem(c.audio.mixwithsystem)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Our first timestep, because window creation can take some time
|
-- Our first timestep, because window creation can take some time
|
||||||
if love.timer then
|
if love.timer then
|
||||||
love.timer.step()
|
love.timer.step()
|
||||||
|
|||||||
@@ -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,
|
0x72, 0x72, 0x65, 0x63, 0x74, 0x28, 0x63, 0x2e, 0x67, 0x61, 0x6d, 0x6d, 0x61, 0x63, 0x6f, 0x72, 0x72, 0x65,
|
||||||
0x63, 0x74, 0x29, 0x0a,
|
0x63, 0x74, 0x29, 0x0a,
|
||||||
0x09, 0x65, 0x6e, 0x64, 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,
|
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,
|
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,
|
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,
|
0x77, 0x2e, 0x69, 0x63, 0x6f, 0x6e, 0x29, 0x29, 0x0a,
|
||||||
0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a,
|
0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a,
|
||||||
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,
|
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,
|
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,
|
0x6f, 0x77, 0x20, 0x63, 0x72, 0x65, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x63, 0x61, 0x6e, 0x20, 0x74, 0x61,
|
||||||
|
|||||||
Reference in New Issue
Block a user