MPlayer slave mode question: how to know when song is done playing?
I have an application that sends and receives commands from mplayer in slave mode (#mplayer -slave -quiet -idle). I need to know when mplayer is done playing all of the files in its playlist (or with the file it was just playing). Currently, mplayer doesn't seem to respond to any commands once it is done playing except 'quit' and 'load <song> <1 or 0>'.
Currently I read the output that mplayer sends out, and call BufferedReader.readline() each time and inspect if the output matches a query I've sent earlier (such as get_property filename). Mplayer will send back ANS_filename=<filename>. But if there is no song currently playing, Mplayer doesn't respond at all, and so readline() blocks indefinitely. A simple solution would be to call BufferedReader.ready() before readline() and see if there is anything on the input buffer, but this is not the 'good' solution because it pretty much depends on the timing of the ready() call. I.e., I could call ready() and it could return false even if mplayer is still playing but hasn't responded quickly enough.
I need to know if mplayer is done playing the song(s) I gave it, that way my application can go query a server for more songs to give mplayer. The timing is important for picking the songs that the server sends back, so I don't want to ask the server for songs until I definitely need to.
Also, I would prefer to keep the current mplayer process alive the whole time (thus the -idle option). I understand mplayer will exit when it's done playing, and thus I can just check if its still alive, but I would prefer not to do that (I'd have to keep track of volume and other properties and such on my application layer so that the state stays the same when I start up a new mplayer client).
Thanks in advance,