diff options
author | der richter <der.richter@gmx.de> | 2020-02-15 16:13:37 +0100 |
---|---|---|
committer | der richter <der.richter@gmx.de> | 2020-02-22 13:56:31 +0100 |
commit | b8f2811f8d180d4c2a39aabc046440c900652bb4 (patch) | |
tree | 6be8c67b9a0a1c5a172f561ceab389e55eb19791 /osdep/macos | |
parent | c1d744328e737fe80ecfdc0cbb6260d7699f4328 (diff) | |
download | mpv-b8f2811f8d180d4c2a39aabc046440c900652bb4.tar.bz2 mpv-b8f2811f8d180d4c2a39aabc046440c900652bb4.tar.xz |
mac: fix media key support for libmpv users
this basically moves the remote command center to our mac events instead
of keeping it our Application, which is only available when started from
mpv itself. also make it independent of the NSApplication.
this also prevents a runtime crash
Diffstat (limited to 'osdep/macos')
-rw-r--r-- | osdep/macos/remote_command_center.swift | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/osdep/macos/remote_command_center.swift b/osdep/macos/remote_command_center.swift index b08a726183..a5dd662737 100644 --- a/osdep/macos/remote_command_center.swift +++ b/osdep/macos/remote_command_center.swift @@ -87,14 +87,10 @@ class RemoteCommandCenter: NSObject { MPRemoteCommandCenter.shared().bookmarkCommand, ] - let application: Application - var mpInfoCenter: MPNowPlayingInfoCenter { get { return MPNowPlayingInfoCenter.default() } } var isPaused: Bool = false { didSet { updatePlaybackState() } } - @objc init(app: Application) { - application = app - + @objc override init() { super.init() for cmd in disabledCommands { @@ -110,8 +106,10 @@ class RemoteCommandCenter: NSObject { } } - if let icon = application.getMPVIcon(), #available(macOS 10.13.2, *) { - let albumArt = MPMediaItemArtwork(boundsSize:icon.size) { _ in + if let app = NSApp as? Application, let icon = app.getMPVIcon(), + #available(macOS 10.13.2, *) + { + let albumArt = MPMediaItemArtwork(boundsSize: icon.size) { _ in return icon } nowPlayingInfo[MPMediaItemPropertyArtwork] = albumArt @@ -119,6 +117,13 @@ class RemoteCommandCenter: NSObject { mpInfoCenter.nowPlayingInfo = nowPlayingInfo mpInfoCenter.playbackState = .playing + + NotificationCenter.default.addObserver( + self, + selector: #selector(self.makeCurrent), + name: NSApplication.willBecomeActiveNotification, + object: nil + ) } @objc func stop() { @@ -131,7 +136,7 @@ class RemoteCommandCenter: NSObject { mpInfoCenter.playbackState = .unknown } - @objc func makeCurrent() { + @objc func makeCurrent(notification: NSNotification) { mpInfoCenter.playbackState = .paused mpInfoCenter.playbackState = .playing updatePlaybackState() @@ -160,7 +165,7 @@ class RemoteCommandCenter: NSObject { } } - application.handleMPKey(mpKey, withMask: Int32(state)); + EventsResponder.sharedInstance().handleMPKey(mpKey, withMask: Int32(state)) return .success } |