summaryrefslogtreecommitdiffhomepage
path: root/lib/media
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2022-09-03 03:40:20 +0100
committerjao <jao@gnu.org>2022-09-03 03:40:20 +0100
commit83674afb2fc90422fd0f9b0c145723c71fd7d4d1 (patch)
tree6b95c689e59a250a6f70839433b7c3359f8fecae /lib/media
parentfa4ca035914c21d3cbacd3c82d4ead5ce814901c (diff)
downloadelibs-83674afb2fc90422fd0f9b0c145723c71fd7d4d1.tar.gz
elibs-83674afb2fc90422fd0f9b0c145723c71fd7d4d1.tar.bz2
jao-mpc: fix for end-of-album detection and nits
Diffstat (limited to 'lib/media')
-rw-r--r--lib/media/jao-mpc.el24
1 files changed, 14 insertions, 10 deletions
diff --git a/lib/media/jao-mpc.el b/lib/media/jao-mpc.el
index 88cde6f..9cdd5bd 100644
--- a/lib/media/jao-mpc.el
+++ b/lib/media/jao-mpc.el
@@ -67,10 +67,13 @@
(jao-mpc--parse-fields s res)
(jao-mpc--parse-fields st res)))
-(defun jao-mpc--playing-p (&optional port)
- (string-prefix-p "playing" (jao-mpc--cmd "status %state%" port)))
+(defsubst jao-mpc-status (&optional port)
+ (string-trim (jao-mpc--cmd "status %state%" port)))
-(defun jao-mpc--queue-len (&optional port)
+(defsubst jao-mpc-playing-p (&optional port)
+ (string-prefix-p "playing" (jao-mpc-status port)))
+
+(defsubst jao-mpc--queue-len (&optional port)
(string-to-number (jao-mpc--cmd "status %length%" port)))
(defsubst jao--put-face (str face)
@@ -110,12 +113,13 @@
(defvar jao-mpc-minibuffer-str "")
(defun jao-mpc--set-current-str (&optional port)
- (setq jao-mpc-minibuffer-str
- (if (jao-mpc--playing-p port)
- (jao-mpc--current-str port)
- (when (and jao-random-album-p (not (jao-mpc--current-str port)))
- (let ((inhibit-message t)) (jao-random-album-next)))
- ""))
+ (let ((status (or (jao-mpc-status port) "")))
+ (setq jao-mpc-minibuffer-str
+ (if (string= "playing" status) (jao-mpc--current-str port) ""))
+ (when (and jao-random-album-p
+ (string= status "paused")
+ (string= "0\n" (jao-mpc--cmd "status %songpos%" port)))
+ (jao-random-album-next)))
(jao-minibuffer-refresh))
(defvar jao-mpc--idle-procs nil)
@@ -288,7 +292,7 @@
(defun jao-mpc-connect (&optional port)
(interactive)
(jao-mpc--idle-loop port)
- (when (jao-mpc--playing-p port) (jao-mpc--set-current-str port)))
+ (when (jao-mpc-playing-p port) (jao-mpc--set-current-str port)))
;;;###autoload
(defun jao-mpc-setup (&optional secondary-port priority)