diff --git a/Persephone/Controllers/QueueViewController.swift b/Persephone/Controllers/QueueViewController.swift index 4f9cb20..d31f6bb 100644 --- a/Persephone/Controllers/QueueViewController.swift +++ b/Persephone/Controllers/QueueViewController.swift @@ -52,6 +52,15 @@ class QueueViewController: NSViewController, NSOutlineViewDataSource, NSOutlineV ) } + @IBAction func playTrack(_ sender: Any) { + guard let view = sender as? NSOutlineView + else { return } + + let queuePos = view.selectedRow - 1 + + AppDelegate.mpdClient.playTrack(queuePos: queuePos) + } + @objc func stateChanged(_ notification: Notification) { guard let state = notification.userInfo?[Notification.stateKey] as? MPDClient.Status.State else { return } diff --git a/Persephone/MPDClient/MPDClient.swift b/Persephone/MPDClient/MPDClient.swift index 87ed839..b2a940e 100644 --- a/Persephone/MPDClient/MPDClient.swift +++ b/Persephone/MPDClient/MPDClient.swift @@ -22,8 +22,8 @@ class MPDClient { private let commandQueue = DispatchQueue(label: "commandQueue") enum Command { - case prevTrack, nextTrack, playPause, stop, fetchStatus, fetchQueue, - fetchAllAlbums + case prevTrack, nextTrack, playPause, stop, + fetchStatus, fetchQueue, fetchAllAlbums } struct Idle: OptionSet { @@ -101,6 +101,14 @@ class MPDClient { queueCommand(command: .nextTrack) } + func playTrack(queuePos: Int) { + noIdle() + commandQueue.async { [unowned self] in + mpd_run_play_pos(self.connection, UInt32(queuePos)) + } + idle() + } + func queueCommand(command: Command) { noIdle() commandQueue.async { [unowned self] in