mirror of
https://github.com/jellyfin/jellyfin-media-player.git
synced 2024-11-27 00:00:38 +00:00
[macOS] show what's currently playing in MPNowPlayingInfoCenter
This commit is contained in:
parent
25affb5b9c
commit
1328d0a548
@ -16,11 +16,14 @@ public:
|
||||
bool initInput() override;
|
||||
const char* inputName() override { return "AppleMediaKeys"; }
|
||||
|
||||
private:
|
||||
void* m_delegate;
|
||||
private slots:
|
||||
void handleStateChanged(PlayerComponent::State newState, PlayerComponent::State oldState);
|
||||
void handlePositionUpdate(quint64 position);
|
||||
void handleUpdateDuration(qint64 duration);
|
||||
void handleUpdateMetaData(const QVariantMap& meta);
|
||||
|
||||
private:
|
||||
void* m_delegate;
|
||||
|
||||
typedef void (*SetNowPlayingVisibilityFunc)(void* origin, int visibility);
|
||||
typedef void* (*GetLocalOriginFunc)(void);
|
||||
|
@ -95,6 +95,8 @@ bool InputAppleMediaKeys::initInput()
|
||||
&InputAppleMediaKeys::handlePositionUpdate);
|
||||
connect(&PlayerComponent::Get(), &PlayerComponent::updateDuration, this,
|
||||
&InputAppleMediaKeys::handleUpdateDuration);
|
||||
connect(&PlayerComponent::Get(), &PlayerComponent::onMetaData, this,
|
||||
&InputAppleMediaKeys::handleUpdateMetaData);
|
||||
|
||||
if (auto lib =
|
||||
dlopen("/System/Library/PrivateFrameworks/MediaRemote.framework/MediaRemote", RTLD_NOW))
|
||||
@ -171,3 +173,37 @@ void InputAppleMediaKeys::handleUpdateDuration(qint64 duration)
|
||||
center.nowPlayingInfo = playingInfo;
|
||||
m_pendingUpdate = true;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void InputAppleMediaKeys::handleUpdateMetaData(const QVariantMap& meta)
|
||||
{
|
||||
auto info = [NSMutableDictionary
|
||||
dictionaryWithDictionary:MPNowPlayingInfoCenter.defaultCenter.nowPlayingInfo];
|
||||
info[MPMediaItemPropertyTitle] = meta["Name"].toString().toNSString();
|
||||
|
||||
if (meta["MediaType"] == QLatin1String{ "Video" })
|
||||
{
|
||||
info[MPNowPlayingInfoPropertyMediaType] = @(MPNowPlayingInfoMediaTypeVideo);
|
||||
if (meta["Type"] == QLatin1String{ "Episode" })
|
||||
{
|
||||
[info addEntriesFromDictionary:@{
|
||||
MPMediaItemPropertyArtist : meta["SeriesName"].toString().toNSString(),
|
||||
MPMediaItemPropertyMediaType : @(MPMediaTypeTVShow),
|
||||
}];
|
||||
}
|
||||
else
|
||||
info[MPMediaItemPropertyMediaType] = @(MPMediaTypeMovie);
|
||||
}
|
||||
else // audio most probably
|
||||
{
|
||||
[info addEntriesFromDictionary:@{
|
||||
MPMediaItemPropertyAlbumArtist : meta["AlbumArtist"].toString().toNSString(),
|
||||
MPMediaItemPropertyAlbumTitle : meta["Album"].toString().toNSString(),
|
||||
MPMediaItemPropertyArtist : meta["Artists"].toStringList().join(", ").toNSString(),
|
||||
MPMediaItemPropertyMediaType : @(MPMediaTypeMusic),
|
||||
MPNowPlayingInfoPropertyMediaType : @(MPNowPlayingInfoMediaTypeAudio),
|
||||
}];
|
||||
}
|
||||
|
||||
MPNowPlayingInfoCenter.defaultCenter.nowPlayingInfo = info;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user