From d39a2aa78b30c051f534db55eba8ce96f2cb4f2c Mon Sep 17 00:00:00 2001 From: Dan Barber Date: Sun, 21 Mar 2021 10:37:55 -0400 Subject: [PATCH] Fix some issues with system Now Playing --- Mac/Components/Shared/MediaInfoController.swift | 6 +++--- Mac/Components/Shared/PlayerStateInfoController.swift | 11 ++++++++++- 2 files changed, 13 insertions(+), 4 deletions(-) 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?) {