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
Daniel Barber ff3c7c4856
Fetching album art via MPD connection now
- Remove music dir prefs
+ Add refresh album art option to album list context menu
+ Wire up album view context menu
+ Force an idle after transport commands
+ Add "clear cache" button
2020-02-15 21:36:38 -05:00

96 lines
2.0 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, priority: .veryHigh, forceIdle: true)
}
func stop() {
enqueueCommand(command: .stop, priority: .veryHigh, forceIdle: true)
}
func prevTrack() {
enqueueCommand(command: .prevTrack, priority: .veryHigh, forceIdle: true)
}
func nextTrack() {
enqueueCommand(command: .nextTrack, priority: .veryHigh, forceIdle: true)
}
func seekCurrentSong(timeInSeconds: Float) {
enqueueCommand(
command: .seekCurrentSong,
priority: .veryHigh,
forceIdle: true,
userData: ["timeInSeconds": timeInSeconds]
)
}
func setShuffleState(shuffleState: Bool) {
enqueueCommand(
command: .setShuffleState,
priority: .veryHigh,
forceIdle: true,
userData: ["shuffleState": shuffleState]
)
}
func setRepeatState(repeatState: Bool) {
enqueueCommand(
command: .setRepeatState,
priority: .veryHigh,
forceIdle: true,
userData: ["repeatState": repeatState]
)
}
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)
}
func sendShuffleState(shuffleState: Bool) {
mpd_run_random(self.connection, shuffleState)
}
func sendRepeatState(repeatState: Bool) {
mpd_run_repeat(self.connection, repeatState)
}
}