1
1
mirror of https://github.com/danbee/persephone synced 2025-03-04 08:39:11 +00:00
persephone/Persephone/MPDClient/Extensions/MPDClient+Transport.swift
Dan Barber 11be238788
Address PR feedback
* Use the OperationQueue's `operationCount` function instead of keeping
count ourselves. This is reliable now each command is entirely self
contained.

* Rename `queueCommand` to `enqueueCommand`

* Move the command Enum into its own model file

* Move the `enqueueCommand` function into MPDClient+Command
2019-03-20 20:06:24 -04:00

68 lines
1.2 KiB
Swift

//
// Transport.swift
// Persephone
//
// Created by Daniel Barber on 2019/3/15.
// Copyright © 2019 Dan Barber. All rights reserved.
//
import Foundation
import mpdclient
extension MPDClient {
func playPause() {
enqueueCommand(command: .playPause)
}
func stop() {
enqueueCommand(command: .stop)
}
func prevTrack() {
enqueueCommand(command: .prevTrack)
}
func nextTrack() {
enqueueCommand(command: .nextTrack)
}
func seekCurrentSong(timeInSeconds: Float) {
enqueueCommand(
command: .seekCurrentSong,
userData: ["timeInSeconds": timeInSeconds]
)
}
func sendNextTrack() {
guard let state = status?.state,
state.isOneOf([.playing, .paused])
else { return }
mpd_run_next(connection)
}
func sendPreviousTrack() {
guard let state = status?.state,
state.isOneOf([.playing, .paused])
else { return }
mpd_run_previous(connection)
}
func sendStop() {
mpd_run_stop(connection)
}
func sendPlay() {
if status?.state == .stopped {
mpd_run_play(connection)
} else {
mpd_run_toggle_pause(connection)
}
}
func sendSeekCurrentSong(timeInSeconds: Float) {
mpd_run_seek_current(self.connection, timeInSeconds, false)
}
}