Closed mihaiolteanu closed 4 years ago
That's a good idea. The easiest way to implement this would be to stick to an asynchronous interface, where you would have to provide a callback to process the response. However a blocking call might be more convenient.
I'm not saying this is the solution, but it might work,
(shell-command-to-string
"echo '{ \"command\": [\"get_property\", \"playback-time\"] }' | socat - /tmp/mpv-fbxEpt")
This is a synchronous call. It passes the mpv command get-property
to socat, which uses the socket opened when the mpv-player was started.
You can then pass the output from this command to a json function,
(require 'json)
(json-read-from-string output-from-prev-command)
If you implement a generic function where "get_property" and "playback-time" can be passed as parameters, you can implement the kind of functions I was talking about in the initial post with just one line of code each.
By the way, I've noticed that you don't clean up the tmp socket files after you close them. I have like 40 files already in my /tmp folder. But that might be the topic of another issue.
I just gave it a go. Can you have a look at the "next" branch and see if it does what you want? There are no specific {get,set}-property commands yet, but you should be able to call
(mpv-run-command "get_property" "playback-time")
(The issue with the stale files should also be fixed on that branch.)
I've tried these,
(mpv-run-command "get_property" "playback-time")
(mpv-run-command "set_property" "playback-time" "0")
They both work as I would expect them to work. Nice! :)
Let me know if you need more input from my side.
I think he easiest interfaces for the users would be something like mpv-playback-time
, mpv-replay
, mpv-rewind
, mpv-length
, etc. for the most used/useful mpv commands. For the most esoteric ones, you can provide this generic interface and the user can study the mpv manual and write his own. At least you're not locking him out if you don't provide the functionality yourself.
These functions are now available on master. Thanks again for the feature request.
I'm not quite sure what you meant by mpv-replay
and mpv-rewind
, though. Do (mpv-cycle-property "loop")
and (mpv-seek 0.0)
come close?
Also, if you feel that any particular (interactive) function is missing, I will gladly add it.
Yes, (mpv-seek 0.0)
would be my (mpv-replay)
and (mpv-seek-backward 5)
would be my (mpv-rewind 5)
.
I've tried your changes and it works great, thank you very much.
Expose a function similar to
mpv--enque
.Something generic, so that calls like
(mpv-command "get_property" "playback-time")
can be possible. The user can then call most of the mpv commands.Or something more specific, so that calls like these and others, can be made possible:
(mpv-get-property "playback-time")
(mpv-set-property "percent-pos" 15)