mirror of
https://github.com/love2d/love.git
synced 2026-08-17 19:23:38 +02:00
Merge default into minor
--HG-- branch : minor
This commit is contained in:
@@ -225,6 +225,22 @@ bool createStorageDirectories()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool hasBackgroundMusic()
|
||||
{
|
||||
JNIEnv *env = (JNIEnv*) SDL_AndroidGetJNIEnv();
|
||||
jobject activity = (jobject) SDL_AndroidGetActivity();
|
||||
|
||||
jclass clazz(env->GetObjectClass(activity));
|
||||
jmethodID method_id = env->GetMethodID(clazz, "hasBackgroundMusic", "()Z");
|
||||
|
||||
jboolean result = env->CallBooleanMethod(activity, method_id);
|
||||
|
||||
env->DeleteLocalRef(activity);
|
||||
env->DeleteLocalRef(clazz);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
} // android
|
||||
} // love
|
||||
|
||||
|
||||
@@ -66,6 +66,8 @@ bool mkdir(const char *path);
|
||||
|
||||
bool createStorageDirectories();
|
||||
|
||||
bool hasBackgroundMusic();
|
||||
|
||||
} // android
|
||||
} // love
|
||||
|
||||
|
||||
@@ -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 mixEnabled);
|
||||
|
||||
/**
|
||||
* Returns whether another application is playing audio.
|
||||
**/
|
||||
bool hasBackgroundMusic();
|
||||
|
||||
} // ios
|
||||
} // love
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#import <AudioToolbox/AudioServices.h>
|
||||
#import <AVFoundation/AVFoundation.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
@@ -344,6 +345,28 @@ void vibrate()
|
||||
}
|
||||
}
|
||||
|
||||
void setAudioMixWithOthers(bool mixEnabled)
|
||||
{
|
||||
@autoreleasepool
|
||||
{
|
||||
NSString *category = AVAudioSessionCategorySoloAmbient;
|
||||
NSError *err;
|
||||
|
||||
if (mixEnabled)
|
||||
category = AVAudioSessionCategoryAmbient;
|
||||
|
||||
if (![[AVAudioSession sharedInstance] setCategory:category error:&err])
|
||||
NSLog(@"Error in AVAudioSession setCategory: %@", [err localizedDescription]);
|
||||
}
|
||||
}
|
||||
|
||||
bool hasBackgroundMusic()
|
||||
{
|
||||
if ([[AVAudioSession sharedInstance] respondsToSelector:@selector(secondaryAudioShouldBeSilencedHint)])
|
||||
return [[AVAudioSession sharedInstance] secondaryAudioShouldBeSilencedHint];
|
||||
return false;
|
||||
}
|
||||
|
||||
} // ios
|
||||
} // love
|
||||
|
||||
|
||||
@@ -25,6 +25,9 @@
|
||||
#include "null/Audio.h"
|
||||
|
||||
#include "common/runtime.h"
|
||||
#ifdef LOVE_IOS
|
||||
#include "common/ios.h"
|
||||
#endif
|
||||
|
||||
// C++
|
||||
#include <iostream>
|
||||
@@ -519,6 +522,17 @@ int w_isEffectsSupported(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifdef LOVE_IOS
|
||||
int w_setMixMode(lua_State *L)
|
||||
{
|
||||
love::ios::setAudioMixWithOthers(lua_toboolean(L, 1));
|
||||
#else
|
||||
int w_setMixMode(lua_State *)
|
||||
{
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
// List of functions to wrap.
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
@@ -549,6 +563,7 @@ static const luaL_Reg functions[] =
|
||||
{ "getMaxSceneEffects", w_getMaxSceneEffects },
|
||||
{ "getMaxSourceEffects", w_getMaxSourceEffects },
|
||||
{ "isEffectsSupported", w_isEffectsSupported },
|
||||
{ "setMixMode", w_setMixMode },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
|
||||
@@ -158,6 +158,17 @@ void System::vibrate(double seconds) const
|
||||
#endif
|
||||
}
|
||||
|
||||
bool System::hasBackgroundMusic() const
|
||||
{
|
||||
#if defined(LOVE_ANDROID)
|
||||
return love::android::hasBackgroundMusic();
|
||||
#elif defined(LOVE_IOS)
|
||||
return love::ios::hasBackgroundMusic();
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool System::getConstant(const char *in, System::PowerState &out)
|
||||
{
|
||||
return powerStates.find(in, out);
|
||||
|
||||
@@ -106,6 +106,14 @@ public:
|
||||
*/
|
||||
virtual void vibrate(double seconds) const;
|
||||
|
||||
/**
|
||||
* Gets if the user is playing music on background.
|
||||
* Throws an exception on unsupported platforms.
|
||||
*
|
||||
* @return Whether a music is playing on background.
|
||||
**/
|
||||
bool hasBackgroundMusic() const;
|
||||
|
||||
static bool getConstant(const char *in, PowerState &out);
|
||||
static bool getConstant(PowerState in, const char *&out);
|
||||
|
||||
|
||||
@@ -95,6 +95,12 @@ int w_vibrate(lua_State *L)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_hasBackgroundMusic(lua_State *L)
|
||||
{
|
||||
lua_pushboolean(L, instance()->hasBackgroundMusic());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "getOS", w_getOS },
|
||||
@@ -104,6 +110,7 @@ static const luaL_Reg functions[] =
|
||||
{ "getPowerInfo", w_getPowerInfo },
|
||||
{ "openURL", w_openURL },
|
||||
{ "vibrate", w_vibrate },
|
||||
{ "hasBackgroundMusic", w_hasBackgroundMusic },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
|
||||
@@ -373,6 +373,9 @@ function love.init()
|
||||
window = true,
|
||||
video = true,
|
||||
},
|
||||
audio = {
|
||||
mixwithsystem = true, -- Only relevant for Android / iOS.
|
||||
},
|
||||
console = false, -- Only relevant for windows.
|
||||
identity = false,
|
||||
appendidentity = false,
|
||||
@@ -492,6 +495,10 @@ function love.init()
|
||||
end
|
||||
end
|
||||
|
||||
if love.audio then
|
||||
love.audio.setMixMode(c.audio.mixwithsystem)
|
||||
end
|
||||
|
||||
-- Our first timestep, because window creation can take some time
|
||||
if love.timer then
|
||||
love.timer.step()
|
||||
|
||||
@@ -684,6 +684,12 @@ 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, 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,
|
||||
0x66, 0x6f, 0x72, 0x20, 0x77, 0x69, 0x6e, 0x64, 0x6f, 0x77, 0x73, 0x2e, 0x0a,
|
||||
@@ -912,6 +918,12 @@ 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, 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,
|
||||
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