Media (Windows): fix compiling for GCC

This commit is contained in:
李通洲
2024-06-11 19:48:25 +08:00
parent cf4ed9d9dc
commit 671f5e2cec
3 changed files with 51 additions and 59 deletions
+40 -33
View File
@@ -8,46 +8,53 @@ extern "C"
const char* ffWinrtDetectMedia(FFWinrtMediaResult* result)
{
// C++/WinRT requires Windows 8.1 or later and C++ runtime (std::string and other stuff)
// 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;
auto manager = GlobalSystemMediaTransportControlsSessionManager::RequestAsync().get();
if (!manager)
return "winrt: GlobalSystemMediaTransportControlsSessionManager::RequestAsync() failed";
auto session = manager.GetCurrentSession();
if (!session)
return "winrt: GetCurrentSession() failed";
auto mediaProps = session
.TryGetMediaPropertiesAsync()
.get();
if (!mediaProps)
return "winrt: TryGetMediaPropertiesAsync() failed";
if (auto playbackInfo = session.GetPlaybackInfo())
try
{
switch (playbackInfo.PlaybackStatus())
auto manager = GlobalSystemMediaTransportControlsSessionManager::RequestAsync().get();
if (!manager)
return "winrt: GlobalSystemMediaTransportControlsSessionManager::RequestAsync() failed";
auto session = manager.GetCurrentSession();
if (!session)
return "winrt: GetCurrentSession() failed";
auto mediaProps = session
.TryGetMediaPropertiesAsync()
.get();
if (!mediaProps)
return "winrt: TryGetMediaPropertiesAsync() failed";
if (auto playbackInfo = session.GetPlaybackInfo())
{
#define FF_MEDIA_SET_STATUS(status_code) \
case GlobalSystemMediaTransportControlsSessionPlaybackStatus::status_code: result->status = #status_code; break
FF_MEDIA_SET_STATUS(Closed);
FF_MEDIA_SET_STATUS(Opened);
FF_MEDIA_SET_STATUS(Changing);
FF_MEDIA_SET_STATUS(Stopped);
FF_MEDIA_SET_STATUS(Playing);
FF_MEDIA_SET_STATUS(Paused);
#undef FF_MEDIA_SET_STATUS
switch (playbackInfo.PlaybackStatus())
{
#define FF_MEDIA_SET_STATUS(status_code) \
case GlobalSystemMediaTransportControlsSessionPlaybackStatus::status_code: result->status = #status_code; break
FF_MEDIA_SET_STATUS(Closed);
FF_MEDIA_SET_STATUS(Opened);
FF_MEDIA_SET_STATUS(Changing);
FF_MEDIA_SET_STATUS(Stopped);
FF_MEDIA_SET_STATUS(Playing);
FF_MEDIA_SET_STATUS(Paused);
#undef FF_MEDIA_SET_STATUS
}
}
::wcsncpy(result->playerId, session.SourceAppUserModelId().data(), FF_MEDIA_WIN_RESULT_BUFLEN);
::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);
return NULL;
}
catch (...)
{
return "A C++ exception is thrown";
}
::wcsncpy(result->playerId, session.SourceAppUserModelId().data(), FF_MEDIA_WIN_RESULT_BUFLEN);
::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);
return NULL;
}
} // extern "C"