From 9ac635e2e6b130bed3a2f679f5261ba5bd1f258b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 13 May 2025 15:46:33 +0800 Subject: [PATCH] Media (Windows): detect player name (UMP apps only) --- src/detection/media/media_windows.c | 13 +++++++++---- src/detection/media/media_windows.dll.cpp | 7 +++++++ src/detection/media/media_windows.dll.h | 1 + 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/detection/media/media_windows.c b/src/detection/media/media_windows.c index cf040f983..54175aa3f 100644 --- a/src/detection/media/media_windows.c +++ b/src/detection/media/media_windows.c @@ -19,11 +19,16 @@ static const char* getMedia(FFMediaResult* media) } ffStrbufSetWS(&media->playerId, result.playerId); - ffStrbufSet(&media->player, &media->playerId); - if (ffStrbufEndsWithIgnCaseS(&media->player, ".exe")) - ffStrbufSubstrBefore(&media->player, media->player.length - 4); + if (result.playerName[0]) + { + ffStrbufSetWS(&media->player, result.playerName); + } else - ffStrbufSubstrAfterFirstC(&media->player, '!'); // UWP ID + { + ffStrbufSet(&media->player, &media->playerId); + if (ffStrbufEndsWithIgnCaseS(&media->player, ".exe")) + ffStrbufSubstrBefore(&media->player, media->player.length - 4); + } ffStrbufSetWS(&media->song, result.song); ffStrbufSetWS(&media->artist, result.artist); ffStrbufSetWS(&media->album, result.album); diff --git a/src/detection/media/media_windows.dll.cpp b/src/detection/media/media_windows.dll.cpp index ff197cf5b..34f46219b 100644 --- a/src/detection/media/media_windows.dll.cpp +++ b/src/detection/media/media_windows.dll.cpp @@ -1,5 +1,6 @@ #include #include +#include #include extern "C" @@ -11,6 +12,7 @@ const char* ffWinrtDetectMedia(FFWinrtMediaResult* result) // C++/WinRT requires Windows 8.1+ and C++ runtime (std::string, exceptions and other stuff) // Make it a separate dll in order not to break Windows 7 support using namespace winrt::Windows::Media::Control; + using namespace winrt::Windows::ApplicationModel; try { @@ -48,6 +50,11 @@ const char* ffWinrtDetectMedia(FFWinrtMediaResult* result) ::wcsncpy(result->song, mediaProps.Title().data(), FF_MEDIA_WIN_RESULT_BUFLEN); ::wcsncpy(result->artist, mediaProps.Artist().data(), FF_MEDIA_WIN_RESULT_BUFLEN); ::wcsncpy(result->album, mediaProps.AlbumTitle().data(), FF_MEDIA_WIN_RESULT_BUFLEN); + try + { + // Only works for UWP apps + ::wcsncpy(result->playerName, AppInfo::GetFromAppUserModelId(session.SourceAppUserModelId()).DisplayInfo().DisplayName().data(), FF_MEDIA_WIN_RESULT_BUFLEN); + } catch (...) { } return NULL; } diff --git a/src/detection/media/media_windows.dll.h b/src/detection/media/media_windows.dll.h index 045976c2e..aae081e88 100644 --- a/src/detection/media/media_windows.dll.h +++ b/src/detection/media/media_windows.dll.h @@ -5,6 +5,7 @@ typedef struct FFWinrtMediaResult { wchar_t playerId[FF_MEDIA_WIN_RESULT_BUFLEN]; + wchar_t playerName[FF_MEDIA_WIN_RESULT_BUFLEN]; wchar_t song[FF_MEDIA_WIN_RESULT_BUFLEN]; wchar_t artist[FF_MEDIA_WIN_RESULT_BUFLEN]; wchar_t album[FF_MEDIA_WIN_RESULT_BUFLEN];