From 9ec70e76b06b1525668a2ee0e31621b377d4fae3 Mon Sep 17 00:00:00 2001 From: Dan Barber Date: Fri, 1 Feb 2019 10:26:05 -0500 Subject: [PATCH] Check playing state before sending next/previous --- Persephone/MPDClient.swift | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/Persephone/MPDClient.swift b/Persephone/MPDClient.swift index 0bb7b9f..cf61b4d 100644 --- a/Persephone/MPDClient.swift +++ b/Persephone/MPDClient.swift @@ -87,11 +87,11 @@ class MPDClient { // Transport commands case .prevTrack: - mpd_run_previous(connection) + sendPreviousTrack() case .nextTrack: - mpd_run_next(connection) + sendNextTrack() case .stop: - mpd_run_stop(connection) + sendStop() case .playPause: sendPlay() @@ -103,6 +103,22 @@ class MPDClient { print(getLastErrorMessage()!) } + func sendNextTrack() { + if getState() == .playing { + mpd_run_next(connection) + } + } + + func sendPreviousTrack() { + if getState() == .playing { + mpd_run_previous(connection) + } + } + + func sendStop() { + mpd_run_stop(connection) + } + func sendPlay() { if getState() == .stopped { mpd_run_play(connection)