mpv-player / mpv

🎥 Command line video player
https://mpv.io
Other
28.25k stars 2.9k forks source link

How can I play a file that was added to an empty playlist in append mode using the IPC JSON API #7525

Closed j-holub closed 4 years ago

j-holub commented 4 years ago

Hey there,

I wasn't really sure if this is an issue or a question, because I don't know if the functionality does not exist or if I just cannot find it. So sorry, if I chose the wrong option.

First things first:

I am developing a NodeJs Wrapper Library for mpv over at Node-MPV and a user of my Library came across an issue that might lie within MPV.

It's about adding a file using loadfile with the mode set to append to an empty playlist. The file is added and not played back, as expected. However, how can I then start the playback? The pause property is already set to false and I cannot find any command in the documentation to just play.

I'm Starting mpv like this

mpv --idle --input-ipc-server=/tmp/mpv.sock

and then appending the file with

echo '{"command": ["loadfile", "somefile.mp3", "append"]}' | socat - /tmp/mpv.sock

which works as expected. The file is added to the playlist and not played. Polling playlist-count outputs 1, also as expected. As said, polling pause via get_property returns false.

Am I just not finding the right command, or is this really a kind of deadlock situation where it's not possible to playback the file?

ghost commented 4 years ago

Setting the playlist-pos property to 0 probably works. Didn't test whether it works as expected, but if it doesn't I'll probably treat it as bug.

j-holub commented 4 years ago

Thanks for the quick reply, I just tested it and as you expected, it does work and the file is played back.

Could you please elaborate briefly on why this works? I will try to add some kind of workaround to my code, until this bug is fixed in a major mpv release and to support mpv version 0.32.0 and below.

ghost commented 4 years ago

I don't consider it a bug that append doesn't start playback (I was talking about playlist-pos). This simply manipulates the playlist while the player remains in idle mode. Now that I looked at the docs, append should indeed not start playback, and append-play exists to cover your use case.

j-holub commented 4 years ago

I don‘t consider it a bug either, that append does not start playback, that is expected behavior. What I meant was, that setting playlist-pos to 0 is completely unintuitive to start the playback. I would‘ve expected either setting pause to false or just having something like a play command. I don’t think anyone that is not familiar with the code base of mpv would think of setting playlist-pos to 0 in order to play the file. That’s what I meant by fixing, unless of course that is the way you think it should be.

But it is something that I can work with and work around. Thanks for the quick response

rohieb commented 4 years ago

Note that loadfile also has an option append-play:

Append the file, and if nothing is currently playing, start playback. (Always starts with the added file, even if the playlist was not empty before running this command.)

j-holub commented 4 years ago

Hey @rohieb , thanks for the suggestion. I'm aware of append-play, but the user that filed the issue on my wrapper library explicitly wants to first set up a playlist by using append multiple times and wants to start playback at some point later in time. That's where we noticed that we didn't know how. And I still think setting playlist-pos to 0 is anything but intuitive and should be changed. But that's not for me to decide, I can work around that with my library and try to make that intuitive.