I have two humble requirements for mpv:
My venerable Lenovo T400 is suprisingly capable at decoding 1080p video, but doing so has an impact on the responsiveness of the system. An easy way to not do unnecessary work is of course to skip decoding video when I am just listening to music in the background:
mpv --no-video <url-or-path-to-video>
During my Emacs craze in moving my workflow over to EXWM, I found out that mpv is well supported in EMMS. As quite some of the music and videos I enjoy can be found on streaming websites, this does add some new conflicting requirements:
While EMMS offers emms-player-mpv-parameters, this only works if I
choose to go with one of the two use-cases; Changing the parameters
only makes a difference before the mpv IPC server is started.
With the help of the fine folks at #mpv on irc.freenode.net, I learned
that you can cycle many properties and options at runtime in mpv, one
of which is the video setting. This leads us to the following snippet:
(defun jlicht/cycle-mpv-video () (interactive) (and (fboundp 'emms-player-mpv-cmd) (emms-player-mpv-cmd '(cycle video))))
Quite short and self-explanatory; if mpv is currently running, it toggles video output (and more importantly, the video decoding with all that entails).
There is a drawback to this approach: if mpv is started with
--no-video, it seems to prevent the video capability from being
loaded in the first place.
Since EXWM is also a tiling window manager, it is annoying to have mpv windows zooming around all over the place when watching several videos in a playlist. Forcing mpv to unconditionally show a window makes this a lot better:
(setq emms-player-mpv-parameters '("--force-window" "--quiet" "--really-quiet" "--no-audio-display"))
This window will simply show a black screen if video output is toggled off. This wouldn't be a post about Emacs without tying it all together in surprisingly simple ways:
(defun play-or-queue-url (url &optional _) (if (and (boundp 'emms-player-playing-p) emms-player-playing-p) (emms-add-url url) (emms-play-url url))) (setq browse-url-handler '(("https:\\/\\/www\\.youtu\\.*be." . play-or-queue-url)))
There you have it: all my requirements met, even the conflicting ones. As an added bonus, youtube links in emacs will now be transparently added to a playlist in emms, such as the ones in Elfeed RSS feeds.