aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Olson <mwolson@gnu.org>2008-07-16 23:06:27 -0700
committerMichael Olson <mwolson@gnu.org>2008-07-16 23:06:27 -0700
commit50dab1d731182939f48ff2c5196c98499c4103a1 (patch)
tree9e0e64f4e6a00b3b238d4d9b988ca94a9a1f4108
parentc0b02ba11520f1bd3f1b419ebc689bb07f0b4133 (diff)
emms-player-mpd: Implement handling of non-EMMS stop of mpd.
* lisp/emms-player-mpd.el (emms-player-mpd-last-state): New variable. (emms-player-mpd-detect-song-change-2): New function that triggers playing time update after a non-EMMS-triggered stop. (emms-player-mpd-detect-song-change-1): Do not disconnect on stop. Implement handling of the case where people run "mpc stop", "mpc start" manually. Have EMMS pick up from where they left off. (emms-player-mpd-clear): Trigger the removal of playing time from the modeline. (emms-player-mpd-disconnect): Clear emms-player-mpd-last-state.
-rw-r--r--lisp/emms-player-mpd.el35
1 files changed, 28 insertions, 7 deletions
diff --git a/lisp/emms-player-mpd.el b/lisp/emms-player-mpd.el
index ba31df4..c1ad17b 100644
--- a/lisp/emms-player-mpd.el
+++ b/lisp/emms-player-mpd.el
@@ -1,6 +1,6 @@
;;; emms-player-mpd.el --- MusicPD support for EMMS
-;; Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
+;; Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
;; Author: Michael Olson <mwolson@gnu.org>
@@ -248,6 +248,7 @@ If your EMMS playlist contains stored playlists, set this to nil."
(make-variable-buffer-local 'emms-player-mpd-playlist-id)
(defvar emms-player-mpd-current-song nil)
+(defvar emms-player-mpd-last-state nil)
(defvar emms-player-mpd-status-timer nil)
(defvar emms-player-mpd-status-regexp
@@ -643,9 +644,17 @@ main EMMS playlist buffer."
(cons emms-playlist-buffer (cons callback closure))
#'emms-player-mpd-sync-from-mpd-1)))
+(defun emms-player-mpd-detect-song-change-2 (state info)
+ "Perform post-sync tasks after returning from a stop."
+ (setq emms-player-mpd-current-song nil)
+ (setq emms-player-playing-p 'emms-player-mpd)
+ (when (string= state "pause")
+ (setq emms-player-paused-p t))
+ (emms-player-mpd-detect-song-change info))
+
(defun emms-player-mpd-detect-song-change-1 (closure info)
(let ((song (emms-player-mpd-get-current-song nil #'ignore info))
- (status (emms-player-mpd-get-mpd-state nil #'ignore info))
+ (state (emms-player-mpd-get-mpd-state nil #'ignore info))
(time (emms-player-mpd-get-playing-time nil #'ignore info))
(err-msg (cdr (assoc "error" info))))
(if (stringp err-msg)
@@ -654,8 +663,8 @@ main EMMS playlist buffer."
(emms-player-mpd-send
"clearerror"
nil #'ignore))
- (cond ((string= status "stop")
- (emms-player-mpd-disconnect t)
+ (cond ((string= state "stop")
+ (setq emms-player-mpd-last-state "stop")
(if song
;; a track remains: the user probably stopped MusicPD
;; manually, so we'll stop EMMS completely
@@ -664,9 +673,17 @@ main EMMS playlist buffer."
;; no more tracks are left: we probably ran out of things
;; to play, so let EMMS do something further if it wants
(emms-player-stopped)))
- ((string= status "pause")
+ ((and emms-player-mpd-last-state
+ (string= emms-player-mpd-last-state "stop"))
+ ;; resume from a stop that occurred outside of EMMS
+ (setq emms-player-mpd-last-state nil)
+ (emms-player-mpd-sync-from-mpd
+ state
+ #'emms-player-mpd-detect-song-change-2))
+ ((string= state "pause")
nil)
- ((string= status "play")
+ ((string= state "play")
+ (setq emms-player-mpd-last-state "play")
(unless (or (null song)
(and (stringp emms-player-mpd-current-song)
(string= song emms-player-mpd-current-song)))
@@ -704,7 +721,10 @@ info from MusicPD."
(when emms-player-mpd-status-timer
(emms-cancel-timer emms-player-mpd-status-timer)
(setq emms-player-mpd-status-timer nil))
- (emms-player-mpd-send "clear" nil #'ignore))
+ (setq emms-player-mpd-last-state nil)
+ (emms-player-mpd-send "clear" nil #'ignore)
+ (let ((emms-player-stopped-p t))
+ (emms-player-stopped)))
;;; Adding to the MusicPD playlist
@@ -931,6 +951,7 @@ from other functions."
(emms-cancel-timer emms-player-mpd-status-timer)
(setq emms-player-mpd-status-timer nil)
(setq emms-player-mpd-current-song nil)
+ (setq emms-player-mpd-last-state nil)
(emms-player-mpd-close-process)
(unless no-stop
(let ((emms-player-stopped-p t))