mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
Support audio mix modes
This commit is contained in:
@@ -64,6 +64,16 @@ std::string getExecutablePath();
|
||||
**/
|
||||
void vibrate();
|
||||
|
||||
/**
|
||||
* Enable mix mode (e.g. with background music apps) and playback with a muted device.
|
||||
**/
|
||||
void setAudioMixWithOthers(bool mixMode, bool playMuted);
|
||||
|
||||
/**
|
||||
* Returns whether another application is playing audio.
|
||||
**/
|
||||
bool audioShouldBeSilenced();
|
||||
|
||||
} // ios
|
||||
} // love
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#import <AudioToolbox/AudioServices.h>
|
||||
#import <AVFoundation/AVFoundation.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
@@ -344,6 +345,39 @@ void vibrate()
|
||||
}
|
||||
}
|
||||
|
||||
void setAudioMixWithOthers(bool mixMode, bool playMuted)
|
||||
{
|
||||
@autoreleasepool
|
||||
{
|
||||
NSError* err;
|
||||
if (mixMode)
|
||||
{
|
||||
if (playMuted)
|
||||
{
|
||||
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionMixWithOthers error:&err];
|
||||
}
|
||||
else
|
||||
{
|
||||
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:&err];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (playMuted)
|
||||
{
|
||||
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&err];
|
||||
}
|
||||
}
|
||||
if (err != nil)
|
||||
NSLog(@"Error in AVAudioSession setCategory: %@", [err localizedDescription]);
|
||||
}
|
||||
}
|
||||
|
||||
bool audioShouldBeSilenced()
|
||||
{
|
||||
return [[AVAudioSession sharedInstance] secondaryAudioShouldBeSilencedHint];
|
||||
}
|
||||
|
||||
} // ios
|
||||
} // love
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "null/Audio.h"
|
||||
|
||||
#include "common/runtime.h"
|
||||
#include "common/ios.h"
|
||||
|
||||
// C++
|
||||
#include <iostream>
|
||||
@@ -293,6 +294,16 @@ int w_getDistanceModel(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_getShouldBeSilenced(lua_State *L)
|
||||
{
|
||||
#ifdef LOVE_IOS
|
||||
lua_pushboolean(L, love::ios::audioShouldBeSilenced());
|
||||
#else
|
||||
lua_pushboolean(L, 0);
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
// List of functions to wrap.
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
@@ -318,6 +329,7 @@ static const luaL_Reg functions[] =
|
||||
{ "stopRecording", w_stopRecording },*/
|
||||
{ "setDistanceModel", w_setDistanceModel },
|
||||
{ "getDistanceModel", w_getDistanceModel },
|
||||
{ "getShouldBeSilenced", w_getShouldBeSilenced },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "common/version.h"
|
||||
#include "common/runtime.h"
|
||||
#include "common/wrap_Data.h"
|
||||
#include "common/ios.h"
|
||||
|
||||
#include "love.h"
|
||||
|
||||
@@ -258,6 +259,14 @@ static int w__setGammaCorrect(lua_State *L)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef LOVE_IOS
|
||||
static int w__setAudioMixMode(lua_State *L)
|
||||
{
|
||||
love::ios::setAudioMixWithOthers(lua_toboolean(L, 1), lua_toboolean(L, 2));
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
int luaopen_love(lua_State *L)
|
||||
{
|
||||
love::luax_insistpinnedthread(L);
|
||||
@@ -291,6 +300,11 @@ int luaopen_love(lua_State *L)
|
||||
lua_pushcfunction(L, w__setGammaCorrect);
|
||||
lua_setfield(L, -2, "_setGammaCorrect");
|
||||
|
||||
#ifdef LOVE_IOS
|
||||
lua_pushcfunction(L, w__setAudioMixMode);
|
||||
lua_setfield(L, -2, "_setAudioMixMode");
|
||||
#endif
|
||||
|
||||
lua_newtable(L);
|
||||
|
||||
for (int i = 0; love::VERSION_COMPATIBILITY[i] != nullptr; i++)
|
||||
|
||||
@@ -373,6 +373,10 @@ function love.init()
|
||||
window = true,
|
||||
video = true,
|
||||
},
|
||||
audio = {
|
||||
mixmode = true,
|
||||
playmuted = false,
|
||||
},
|
||||
console = false, -- Only relevant for windows.
|
||||
identity = false,
|
||||
appendidentity = false,
|
||||
@@ -416,6 +420,10 @@ function love.init()
|
||||
love._setGammaCorrect(c.gammacorrect)
|
||||
end
|
||||
|
||||
if love._setAudioMixMode then
|
||||
love._setAudioMixMode(c.audio.mixmode, c.audio.playmuted)
|
||||
end
|
||||
|
||||
-- Gets desired modules.
|
||||
for k,v in ipairs{
|
||||
"thread",
|
||||
|
||||
@@ -682,6 +682,11 @@ const unsigned char boot_lua[] =
|
||||
0x09, 0x09, 0x09, 0x77, 0x69, 0x6e, 0x64, 0x6f, 0x77, 0x20, 0x3d, 0x20, 0x74, 0x72, 0x75, 0x65, 0x2c, 0x0a,
|
||||
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, 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,
|
||||
0x66, 0x6f, 0x72, 0x20, 0x77, 0x69, 0x6e, 0x64, 0x6f, 0x77, 0x73, 0x2e, 0x0a,
|
||||
@@ -776,6 +781,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, 0x4d, 0x6f, 0x64, 0x65, 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, 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,
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user