diff --git a/Mac/Components/Shared/MediaInfoController.swift b/Mac/Components/Shared/MediaInfoController.swift index 882923f..2b8fd3a 100644 --- a/Mac/Components/Shared/MediaInfoController.swift +++ b/Mac/Components/Shared/MediaInfoController.swift @@ -14,7 +14,7 @@ import Kingfisher class MediaInfoController { init() { App.store.subscribe(self) { - $0.select { $0.playerState.currentSong } + $0.select { $0.playerState } } } @@ -66,10 +66,10 @@ class MediaInfoController { } extension MediaInfoController: StoreSubscriber { - typealias StoreSubscriberStateType = Song? + typealias StoreSubscriberStateType = PlayerState? func newState(state: StoreSubscriberStateType) { - guard let song = state else {return} + guard let song = state?.currentSong else { return } notifyTrack(song) } diff --git a/Mac/Components/Shared/PlayerStateInfoController.swift b/Mac/Components/Shared/PlayerStateInfoController.swift index ff6104f..a78c78c 100644 --- a/Mac/Components/Shared/PlayerStateInfoController.swift +++ b/Mac/Components/Shared/PlayerStateInfoController.swift @@ -12,11 +12,13 @@ import MediaPlayer import Kingfisher class PlayerStateInfoController { + let commandCenter = MPRemoteCommandCenter.shared() + init() { App.store.subscribe(self) { $0.select { $0.playerState.state } } - let commandCenter = MPRemoteCommandCenter.shared() + commandCenter.playCommand.addTarget { _ in App.mpdClient.playPause() return .success @@ -39,6 +41,13 @@ class PlayerStateInfoController { App.mpdClient.prevTrack() return .success } + + commandCenter.changePlaybackPositionCommand.addTarget { event in + let changeEvent = event as! MPChangePlaybackPositionCommandEvent + + App.mpdClient.seekCurrentSong(timeInSeconds: Float(changeEvent.positionTime)) + return .success + } } func notifyState(_ state: MPDClient.MPDStatus.State?) {