reddit / emacs

Control EMMS/MPV volume

EcstaticBill2638 · 2022-02-22 14:18
Hi all, thought I'd share a way to control the volume of EMMS using MPV as a backend. I couldn't find any solutions on the net, and this took quite a bit of trial and error so hopefully this will save you some pain. (defvar emms-player-mpv-volume 100) (defun emms-player-mpv-get-volume () "Sets `emms-player-mpv-volume' to the current volume value and sends a message of the current volume status." (emms-player-mpv-cmd '(get_property volume) #'(lambda (vol err) (unless err (let ((vol (truncate vol))) (setq emms-player-mpv-volume vol) (message "Music volume: %s%%" vol)))))) (defun emms-player-mpv-raise-volume (&optional amount) (interactive) (let* ((amount (or amount 10)) (new-volume (+ emms-player-mpv-volume amount))) (if (> new-volume 100) (emms-player-mpv-cmd '(set_property volume 100)) (emms-player-mpv-cmd `(add volume ,amount)))) (emms-player-mpv-get-volume)) (defun emms-player-mpv-lower-volume (&optional amount) (interactive) (emms-player-mpv-cmd `(add volume ,(- (or amount '10)))) (emms-player-mpv-get-volume)) For reference my `emms-player-mpv-parameters` is set to `'("--quiet" "--really-quiet" "--no-audio-display" "--force-window=no" "--vo=null" "--no-resume-playback")`
funk443 · 2022-06-09 18:47
Thank you man!
ivchoniboy · 2022-08-31 21:04
Awesome, thanks! Works like a charm. Note that one thing to set also is the \`emms-volume-change-function\` to "emms-volume-mpd-change". (Another thing is that on MacOS the volume up does not really work as expected, i.e. it gets limited at like 50%, but that's probably an OS-specific thing, that needs to be fixed independently.)