Skip to content

Commit 9ac635e

Browse files
committed
Media (Windows): detect player name (UMP apps only)
1 parent 1b1b052 commit 9ac635e

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

src/detection/media/media_windows.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,16 @@ static const char* getMedia(FFMediaResult* media)
1919
}
2020

2121
ffStrbufSetWS(&media->playerId, result.playerId);
22-
ffStrbufSet(&media->player, &media->playerId);
23-
if (ffStrbufEndsWithIgnCaseS(&media->player, ".exe"))
24-
ffStrbufSubstrBefore(&media->player, media->player.length - 4);
22+
if (result.playerName[0])
23+
{
24+
ffStrbufSetWS(&media->player, result.playerName);
25+
}
2526
else
26-
ffStrbufSubstrAfterFirstC(&media->player, '!'); // UWP ID
27+
{
28+
ffStrbufSet(&media->player, &media->playerId);
29+
if (ffStrbufEndsWithIgnCaseS(&media->player, ".exe"))
30+
ffStrbufSubstrBefore(&media->player, media->player.length - 4);
31+
}
2732
ffStrbufSetWS(&media->song, result.song);
2833
ffStrbufSetWS(&media->artist, result.artist);
2934
ffStrbufSetWS(&media->album, result.album);

src/detection/media/media_windows.dll.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <winrt/Windows.Foundation.h>
22
#include <winrt/Windows.Media.Control.h>
3+
#include <winrt/Windows.ApplicationModel.h>
34
#include <wchar.h>
45

56
extern "C"
@@ -11,6 +12,7 @@ const char* ffWinrtDetectMedia(FFWinrtMediaResult* result)
1112
// C++/WinRT requires Windows 8.1+ and C++ runtime (std::string, exceptions and other stuff)
1213
// Make it a separate dll in order not to break Windows 7 support
1314
using namespace winrt::Windows::Media::Control;
15+
using namespace winrt::Windows::ApplicationModel;
1416

1517
try
1618
{
@@ -48,6 +50,11 @@ const char* ffWinrtDetectMedia(FFWinrtMediaResult* result)
4850
::wcsncpy(result->song, mediaProps.Title().data(), FF_MEDIA_WIN_RESULT_BUFLEN);
4951
::wcsncpy(result->artist, mediaProps.Artist().data(), FF_MEDIA_WIN_RESULT_BUFLEN);
5052
::wcsncpy(result->album, mediaProps.AlbumTitle().data(), FF_MEDIA_WIN_RESULT_BUFLEN);
53+
try
54+
{
55+
// Only works for UWP apps
56+
::wcsncpy(result->playerName, AppInfo::GetFromAppUserModelId(session.SourceAppUserModelId()).DisplayInfo().DisplayName().data(), FF_MEDIA_WIN_RESULT_BUFLEN);
57+
} catch (...) { }
5158

5259
return NULL;
5360
}

src/detection/media/media_windows.dll.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
typedef struct FFWinrtMediaResult
66
{
77
wchar_t playerId[FF_MEDIA_WIN_RESULT_BUFLEN];
8+
wchar_t playerName[FF_MEDIA_WIN_RESULT_BUFLEN];
89
wchar_t song[FF_MEDIA_WIN_RESULT_BUFLEN];
910
wchar_t artist[FF_MEDIA_WIN_RESULT_BUFLEN];
1011
wchar_t album[FF_MEDIA_WIN_RESULT_BUFLEN];

0 commit comments

Comments
 (0)