mirror of https://github.com/mpv-player/mpv
mac/remote: remove unnecessary nowPlayingInfo variable
no need to keep track of the nowPlayingInfo, MPNowPlayingInfoCenter already provides the current info.
This commit is contained in:
parent
e457cc260c
commit
45192d94d3
|
@ -40,7 +40,6 @@ extension RemoteCommandCenter {
|
|||
}
|
||||
|
||||
class RemoteCommandCenter: NSObject {
|
||||
var nowPlayingInfo: [String:Any] = [:]
|
||||
var configs: [MPRemoteCommand:Config] = [:]
|
||||
var disabledCommands: [MPRemoteCommand] = []
|
||||
var isPaused: Bool = false { didSet { updateInfoCenter() } }
|
||||
|
@ -51,6 +50,7 @@ class RemoteCommandCenter: NSObject {
|
|||
var chapter: String? { didSet { updateInfoCenter() } }
|
||||
var album: String? { didSet { updateInfoCenter() } }
|
||||
var artist: String? { didSet { updateInfoCenter() } }
|
||||
var cover: NSImage = NSImage(size: NSSize(width: 256, height: 256))
|
||||
|
||||
var infoCenter: MPNowPlayingInfoCenter { get { return MPNowPlayingInfoCenter.default() } }
|
||||
var commandCenter: MPRemoteCommandCenter { get { return MPRemoteCommandCenter.shared() } }
|
||||
|
@ -58,11 +58,6 @@ class RemoteCommandCenter: NSObject {
|
|||
@objc override init() {
|
||||
super.init()
|
||||
|
||||
nowPlayingInfo = [
|
||||
MPNowPlayingInfoPropertyMediaType: NSNumber(value: MPNowPlayingInfoMediaType.video.rawValue),
|
||||
MPNowPlayingInfoPropertyPlaybackProgress: NSNumber(value: 0.0),
|
||||
]
|
||||
|
||||
configs = [
|
||||
commandCenter.pauseCommand: Config(key: MP_KEY_PAUSEONLY, handler: keyHandler),
|
||||
commandCenter.playCommand: Config(key: MP_KEY_PLAYONLY, handler: keyHandler),
|
||||
|
@ -90,10 +85,7 @@ class RemoteCommandCenter: NSObject {
|
|||
]
|
||||
|
||||
if let app = NSApp as? Application, let icon = app.getMPVIcon() {
|
||||
let albumArt = MPMediaItemArtwork(boundsSize: icon.size) { _ in
|
||||
return icon
|
||||
}
|
||||
nowPlayingInfo[MPMediaItemPropertyArtwork] = albumArt
|
||||
cover = icon
|
||||
}
|
||||
|
||||
for cmd in disabledCommands {
|
||||
|
@ -140,17 +132,18 @@ class RemoteCommandCenter: NSObject {
|
|||
}
|
||||
|
||||
func updateInfoCenter() {
|
||||
nowPlayingInfo.merge([
|
||||
infoCenter.playbackState = isPaused ? .paused : .playing
|
||||
infoCenter.nowPlayingInfo = (infoCenter.nowPlayingInfo ?? [:]).merging([
|
||||
MPNowPlayingInfoPropertyMediaType: NSNumber(value: MPNowPlayingInfoMediaType.video.rawValue),
|
||||
MPNowPlayingInfoPropertyPlaybackProgress: NSNumber(value: 0.0),
|
||||
MPNowPlayingInfoPropertyPlaybackRate: NSNumber(value: isPaused ? 0 : rate),
|
||||
MPNowPlayingInfoPropertyElapsedPlaybackTime: NSNumber(value: position),
|
||||
MPMediaItemPropertyPlaybackDuration: NSNumber(value: duration),
|
||||
MPMediaItemPropertyTitle: title,
|
||||
MPMediaItemPropertyArtist: artist ?? chapter ?? "",
|
||||
MPMediaItemPropertyAlbumTitle: album ?? "",
|
||||
MPMediaItemPropertyArtwork: MPMediaItemArtwork(boundsSize: cover.size) { _ in return self.cover }
|
||||
]) { (_, new) in new }
|
||||
|
||||
infoCenter.nowPlayingInfo = nowPlayingInfo
|
||||
infoCenter.playbackState = isPaused ? .paused : .playing
|
||||
}
|
||||
|
||||
lazy var keyHandler: ConfigHandler = { event in
|
||||
|
|
Loading…
Reference in New Issue