1
1
mirror of https://github.com/danbee/persephone synced 2025-03-04 08:39:11 +00:00

Fix some issues with system Now Playing

This commit is contained in:
Daniel Barber 2021-03-21 10:37:55 -04:00
parent 1135a96f38
commit d39a2aa78b
2 changed files with 13 additions and 4 deletions

View File

@ -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)
}

View File

@ -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?) {