diff options
author | der richter <der.richter@gmx.de> | 2020-01-21 19:14:00 +0100 |
---|---|---|
committer | der richter <der.richter@gmx.de> | 2020-01-26 12:09:55 +0100 |
commit | 695d850412144629827bdea146e6bf4bbeba39ed (patch) | |
tree | 119dec09e5401548e059f5898868d1fed56bcfb7 /osdep/macos | |
parent | 3d16ab1a311d16cd5a07feca916494869a80d264 (diff) | |
download | mpv-695d850412144629827bdea146e6bf4bbeba39ed.tar.bz2 mpv-695d850412144629827bdea146e6bf4bbeba39ed.tar.xz |
mac: report playback state to the MediaPlayer Command Center
some system logic for the global media key events depends on the right
playback state. set the state properly to prevent more breakages in the
future.
Diffstat (limited to 'osdep/macos')
-rw-r--r-- | osdep/macos/remote_command_center.swift | 53 |
1 files changed, 42 insertions, 11 deletions
diff --git a/osdep/macos/remote_command_center.swift b/osdep/macos/remote_command_center.swift index 7d6e51081c..b08a726183 100644 --- a/osdep/macos/remote_command_center.swift +++ b/osdep/macos/remote_command_center.swift @@ -87,7 +87,10 @@ class RemoteCommandCenter: NSObject { MPRemoteCommandCenter.shared().bookmarkCommand, ] - let application: Application; + let application: Application + + var mpInfoCenter: MPNowPlayingInfoCenter { get { return MPNowPlayingInfoCenter.default() } } + var isPaused: Bool = false { didSet { updatePlaybackState() } } @objc init(app: Application) { application = app @@ -99,11 +102,6 @@ class RemoteCommandCenter: NSObject { } } - @objc func makeCurrent() { - MPNowPlayingInfoCenter.default().playbackState = .paused - MPNowPlayingInfoCenter.default().playbackState = .playing - } - @objc func start() { for (cmd, _) in config { cmd.isEnabled = true @@ -119,8 +117,8 @@ class RemoteCommandCenter: NSObject { nowPlayingInfo[MPMediaItemPropertyArtwork] = albumArt } - MPNowPlayingInfoCenter.default().nowPlayingInfo = nowPlayingInfo - MPNowPlayingInfoCenter.default().playbackState = .playing + mpInfoCenter.nowPlayingInfo = nowPlayingInfo + mpInfoCenter.playbackState = .playing } @objc func stop() { @@ -129,8 +127,18 @@ class RemoteCommandCenter: NSObject { cmd.removeTarget(nil) } - MPNowPlayingInfoCenter.default().nowPlayingInfo = nil - MPNowPlayingInfoCenter.default().playbackState = .unknown + mpInfoCenter.nowPlayingInfo = nil + mpInfoCenter.playbackState = .unknown + } + + @objc func makeCurrent() { + mpInfoCenter.playbackState = .paused + mpInfoCenter.playbackState = .playing + updatePlaybackState() + } + + func updatePlaybackState() { + mpInfoCenter.playbackState = isPaused ? .paused : .playing } func cmdHandler(_ event: MPRemoteCommandEvent) -> MPRemoteCommandHandlerStatus { @@ -156,4 +164,27 @@ class RemoteCommandCenter: NSObject { return .success } -}
\ No newline at end of file + + @objc func processEvent(_ event: UnsafeMutablePointer<mpv_event>) { + switch event.pointee.event_id { + case MPV_EVENT_PROPERTY_CHANGE: + handlePropertyChange(event) + default: + break + } + } + + func handlePropertyChange(_ event: UnsafeMutablePointer<mpv_event>) { + let pData = OpaquePointer(event.pointee.data) + guard let property = UnsafePointer<mpv_event_property>(pData)?.pointee else { + return + } + + switch String(cString: property.name) { + case "pause" where property.format == MPV_FORMAT_FLAG: + isPaused = LibmpvHelper.mpvFlagToBool(property.data) ?? false + default: + break + } + } +} |