mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2026-03-03 11:29:59 -06:00
Move media playback detection to OS namespace
This commit is contained in:
7
UnleashedRecomp/os/media.cpp
Normal file
7
UnleashedRecomp/os/media.cpp
Normal file
@@ -0,0 +1,7 @@
|
||||
#include <os/media.h>
|
||||
#include <os/media_detail.h>
|
||||
|
||||
bool os::media::IsExternalMediaPlaying()
|
||||
{
|
||||
return detail::IsExternalMediaPlaying();
|
||||
}
|
||||
6
UnleashedRecomp/os/media.h
Normal file
6
UnleashedRecomp/os/media.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
namespace os::media
|
||||
{
|
||||
bool IsExternalMediaPlaying();
|
||||
}
|
||||
6
UnleashedRecomp/os/media_detail.h
Normal file
6
UnleashedRecomp/os/media_detail.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
namespace os::media::detail
|
||||
{
|
||||
bool IsExternalMediaPlaying();
|
||||
}
|
||||
72
UnleashedRecomp/os/win32/media_win32.cpp
Normal file
72
UnleashedRecomp/os/win32/media_win32.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
#include <os/media_detail.h>
|
||||
#include <winrt/Windows.Foundation.h>
|
||||
#include <winrt/Windows.Media.Control.h>
|
||||
|
||||
using namespace winrt;
|
||||
using namespace winrt::Windows::Foundation;
|
||||
using namespace winrt::Windows::Media::Control;
|
||||
|
||||
static GlobalSystemMediaTransportControlsSessionManager g_sessionManager = nullptr;
|
||||
|
||||
static GlobalSystemMediaTransportControlsSessionManager GetSessionManager()
|
||||
{
|
||||
if (g_sessionManager)
|
||||
return g_sessionManager;
|
||||
|
||||
try
|
||||
{
|
||||
init_apartment();
|
||||
return g_sessionManager = GlobalSystemMediaTransportControlsSessionManager::RequestAsync().get();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
printf("[*] Failed to retrieve GSMTC session manager: 0x%08X\n", to_hresult().value);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
static GlobalSystemMediaTransportControlsSession GetCurrentSession()
|
||||
{
|
||||
auto sessionManager = GetSessionManager();
|
||||
|
||||
if (!sessionManager)
|
||||
return nullptr;
|
||||
|
||||
try
|
||||
{
|
||||
return sessionManager.GetCurrentSession();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
printf("[*] Failed to retrieve current GSMTC session: 0x%08X\n", to_hresult().value);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
static GlobalSystemMediaTransportControlsSessionPlaybackInfo GetPlaybackInfo()
|
||||
{
|
||||
auto session = GetCurrentSession();
|
||||
|
||||
if (!session)
|
||||
return nullptr;
|
||||
|
||||
try
|
||||
{
|
||||
return session.GetPlaybackInfo();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
printf("[*] Failed to retrieve GSMTC playback info: 0x%08X\n", to_hresult().value);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool os::media::detail::IsExternalMediaPlaying()
|
||||
{
|
||||
auto playbackInfo = GetPlaybackInfo();
|
||||
|
||||
if (!playbackInfo)
|
||||
return false;
|
||||
|
||||
return playbackInfo.PlaybackStatus() == GlobalSystemMediaTransportControlsSessionPlaybackStatus::Playing;
|
||||
}
|
||||
Reference in New Issue
Block a user