mpv.el icon indicating copy to clipboard operation
mpv.el copied to clipboard

Add a backward compatible function of mpv playlist-play-index

Open firmart opened this issue 3 years ago • 4 comments

The mpv command playlist-play-index was only introduced recently in version 0.33. It would be useful to have a backward compatible wrapper for people haven't upgraded their mpv build.

P.S. Maybe we can make it interactive.

firmart avatar Feb 08 '21 00:02 firmart

Thanks, I'll have a look. In general I'd like to keep this library slim, so I wouldn't want to add too many extra functions. But if playlist-play-index is important for your workflow (or some other package) we can add it (also considering that 0.33 is not available yet for several widely used distributions).

kljohann avatar Feb 27 '21 09:02 kljohann

Thank you. Yes, it would be useful/fundamental for some package like vuiet to be able to jump around in a playlist. This PR comes from a misunderstanding that any command in the mpv documentation would work with mpv-run-command. However, (mpv-run-command "playlist-play-index" 0) simply doesn't work for mpv version prior to 0.33.

firmart avatar Feb 27 '21 23:02 firmart

I fixed the code to reflect your suggestions. I wasn't able to test the case whenever playlist-pos returns -1, because I don't know exactly how to remove the current flag. Maybe I simply can't with my mpv version v0.32. I tried both (mpv-set-property "playlist-pos" -1) and (mpv-set-property "playlist-current-pos" -1). The former raised the error unsupported format for accessing format and the latter raised property not found.

As you said, (mpv-set-property "playlist-pos" pos) does work, though the documentation says

Writing the current value back to the property is subject to change. 
Currently, it will restart playback of the playlist entry. 
But in the future, writing the current value will be ignored. 
Use the playlist-play-index command to get guaranteed behavior.

we are fine as mpv version 0.33 won't go through this path. So I replaced the cl-loop.

firmart avatar Mar 10 '21 15:03 firmart

Looks good! On 0.33 I can get playlist-pos = -1 by starting mpv with --idle=yes or --idle=once. It will be -1 initially if no filename has been provided, and, in the case of --idle=yes, also after playback has finished:

(mpv-start "--idle=once")
(mpv-get-property "playlist-pos") ;; returns `-1` on 0.33

(mpv-start "--idle=yes" "https://www.youtube.com/watch?v=ylXk1LBvIqU")
;; ... wait until playlist has finished playing ...
(mpv-get-property "playlist-pos") ;; returns `-1` on 0.33

Can you give this a try on 0.32?

kljohann avatar Mar 13 '21 11:03 kljohann