mac/remote: add album and artist info

This commit is contained in:
der richter 2024-02-13 21:47:21 +01:00
parent c56be84675
commit e457cc260c
2 changed files with 12 additions and 3 deletions

View File

@ -48,7 +48,9 @@ class RemoteCommandCenter: NSObject {
var position: Double = 0 { didSet { updateInfoCenter() } }
var rate: Double = 0 { didSet { updateInfoCenter() } }
var title: String = "" { didSet { updateInfoCenter() } }
var chapter: String = "" { didSet { updateInfoCenter() } }
var chapter: String? { didSet { updateInfoCenter() } }
var album: String? { didSet { updateInfoCenter() } }
var artist: String? { didSet { updateInfoCenter() } }
var infoCenter: MPNowPlayingInfoCenter { get { return MPNowPlayingInfoCenter.default() } }
var commandCenter: MPRemoteCommandCenter { get { return MPRemoteCommandCenter.shared() } }
@ -143,7 +145,8 @@ class RemoteCommandCenter: NSObject {
MPNowPlayingInfoPropertyElapsedPlaybackTime: NSNumber(value: position),
MPMediaItemPropertyPlaybackDuration: NSNumber(value: duration),
MPMediaItemPropertyTitle: title,
MPMediaItemPropertyArtist: chapter,
MPMediaItemPropertyArtist: artist ?? chapter ?? "",
MPMediaItemPropertyAlbumTitle: album ?? "",
]) { (_, new) in new }
infoCenter.nowPlayingInfo = nowPlayingInfo
@ -208,7 +211,11 @@ class RemoteCommandCenter: NSObject {
case "media-title" where [MPV_FORMAT_STRING, MPV_FORMAT_NONE].contains(property.format):
title = LibmpvHelper.mpvStringArrayToString(property.data) ?? ""
case "chapter-metadata/title" where [MPV_FORMAT_STRING, MPV_FORMAT_NONE].contains(property.format):
chapter = LibmpvHelper.mpvStringArrayToString(property.data) ?? ""
chapter = LibmpvHelper.mpvStringArrayToString(property.data)
case "metadata/by-key/album" where [MPV_FORMAT_STRING, MPV_FORMAT_NONE].contains(property.format):
album = LibmpvHelper.mpvStringArrayToString(property.data)
case "metadata/by-key/artist" where [MPV_FORMAT_STRING, MPV_FORMAT_NONE].contains(property.format):
artist = LibmpvHelper.mpvStringArrayToString(property.data)
default:
break
}

View File

@ -160,6 +160,8 @@ void cocoa_set_mpv_handle(struct mpv_handle *ctx)
mpv_observe_property(ctx, 0, "pause", MPV_FORMAT_FLAG);
mpv_observe_property(ctx, 0, "media-title", MPV_FORMAT_STRING);
mpv_observe_property(ctx, 0, "chapter-metadata/title", MPV_FORMAT_STRING);
mpv_observe_property(ctx, 0, "metadata/by-key/album", MPV_FORMAT_STRING);
mpv_observe_property(ctx, 0, "metadata/by-key/artist", MPV_FORMAT_STRING);
mpv_set_wakeup_callback(ctx, wakeup, NULL);
}
}