1
1
mirror of https://github.com/danbee/persephone synced 2025-03-04 08:39:11 +00:00
persephone/Persephone/MPDClient/Extensions/MPDClient+Queue.swift
Dan Barber fe748e2c61
WIP: Refactor MPDClient
This should make handling the queuing side work more reliably.
2019-03-20 20:06:23 -04:00

39 lines
798 B
Swift

//
// Queue.swift
// Persephone
//
// Created by Daniel Barber on 2019/3/15.
// Copyright © 2019 Dan Barber. All rights reserved.
//
import Foundation
import mpdclient
extension MPDClient {
func fetchQueue() {
sendCommand(command: .fetchQueue)
}
func playTrack(queuePos: Int) {
guard isConnected else { return }
noIdle()
let commandOperation = BlockOperation { [unowned self] in
mpd_run_play_pos(self.connection, UInt32(queuePos))
}
commandOperation.queuePriority = .veryHigh
commandQueue.addOperation(commandOperation)
idle()
}
func sendFetchQueue() {
self.queue = []
mpd_send_list_queue_meta(connection)
while let mpdSong = mpd_recv_song(connection) {
let song = Song(mpdSong)
self.queue.append(song)
}
}
}