mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
Add Android support to hasBackgroundMusic
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
|
||||
|
||||
|
||||
@@ -307,16 +307,6 @@ int w_setMixMode(lua_State *)
|
||||
return 0;
|
||||
}
|
||||
|
||||
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[] =
|
||||
{
|
||||
@@ -343,7 +333,6 @@ static const luaL_Reg functions[] =
|
||||
{ "setDistanceModel", w_setDistanceModel },
|
||||
{ "getDistanceModel", w_getDistanceModel },
|
||||
{ "setMixMode", w_setMixMode },
|
||||
{ "getShouldBeSilenced", w_getShouldBeSilenced },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
|
||||
@@ -184,6 +184,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::audioShouldBeSilenced();
|
||||
#else
|
||||
throw love::Exception("Unsupported platform.");
|
||||
#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);
|
||||
|
||||
|
||||
@@ -93,6 +93,19 @@ int w_vibrate(lua_State *L)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_hasBackgroundMusic(lua_State *L)
|
||||
{
|
||||
try
|
||||
{
|
||||
lua_pushboolean(L, instance()->hasBackgroundMusic());
|
||||
}
|
||||
catch (love::Exception &)
|
||||
{
|
||||
lua_pushnil(L);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "getOS", w_getOS },
|
||||
@@ -102,6 +115,7 @@ static const luaL_Reg functions[] =
|
||||
{ "getPowerInfo", w_getPowerInfo },
|
||||
{ "openURL", w_openURL },
|
||||
{ "vibrate", w_vibrate },
|
||||
{ "hasBackgroundMusic", w_hasBackgroundMusic },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user