diff --git a/UnleashedRecomp/os/linux/media_linux.cpp b/UnleashedRecomp/os/linux/media_linux.cpp index 91347193..0274508c 100644 --- a/UnleashedRecomp/os/linux/media_linux.cpp +++ b/UnleashedRecomp/os/linux/media_linux.cpp @@ -2,6 +2,13 @@ #include #include +#include "app.h" + +#define MEDIA_CHECK_RATE 1 + +static float g_mediaCheckTimer; +static bool g_mediaLastResult; + static DBusConnection* CreateDBusConnection() { DBusError dbusError; @@ -170,6 +177,13 @@ static bool IsMediaPlayerPlaying(DBusConnection* connection, const std::string& 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(); if (!dbusConnection) return false; @@ -187,5 +201,6 @@ bool os::media::IsExternalMediaPlaying() } DestroyDBusConnection(dbusConnection); + g_mediaLastResult = result; return result; } \ No newline at end of file