mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2026-04-26 04:11:36 +00:00
Run Linux music attenuation code on timer
This commit is contained in:
parent
11181136d8
commit
a75f88ed1a
1 changed files with 15 additions and 0 deletions
|
|
@ -2,6 +2,13 @@
|
||||||
#include <os/logger.h>
|
#include <os/logger.h>
|
||||||
#include <dbus/dbus.h>
|
#include <dbus/dbus.h>
|
||||||
|
|
||||||
|
#include "app.h"
|
||||||
|
|
||||||
|
#define MEDIA_CHECK_RATE 1
|
||||||
|
|
||||||
|
static float g_mediaCheckTimer;
|
||||||
|
static bool g_mediaLastResult;
|
||||||
|
|
||||||
static DBusConnection* CreateDBusConnection()
|
static DBusConnection* CreateDBusConnection()
|
||||||
{
|
{
|
||||||
DBusError dbusError;
|
DBusError dbusError;
|
||||||
|
|
@ -170,6 +177,13 @@ static bool IsMediaPlayerPlaying(DBusConnection* connection, const std::string&
|
||||||
|
|
||||||
bool os::media::IsExternalMediaPlaying()
|
bool os::media::IsExternalMediaPlaying()
|
||||||
{
|
{
|
||||||
|
//Calling D-Bus functions too much seems cause D-Bus to stop working, so perhaps it should be run less often.
|
||||||
|
g_mediaCheckTimer -= App::s_deltaTime;
|
||||||
|
if (g_mediaCheckTimer > 0)
|
||||||
|
return g_mediaLastResult;
|
||||||
|
|
||||||
|
g_mediaCheckTimer = MEDIA_CHECK_RATE;
|
||||||
|
|
||||||
const auto dbusConnection = CreateDBusConnection();
|
const auto dbusConnection = CreateDBusConnection();
|
||||||
if (!dbusConnection)
|
if (!dbusConnection)
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -187,5 +201,6 @@ bool os::media::IsExternalMediaPlaying()
|
||||||
}
|
}
|
||||||
|
|
||||||
DestroyDBusConnection(dbusConnection);
|
DestroyDBusConnection(dbusConnection);
|
||||||
|
g_mediaLastResult = result;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
Loading…
Add table
Reference in a new issue