Reputation: 29
I have a python script that controls (via a named pipe) an instance of mplayer in slave mode that's playing MP3s. Everything works as expected, but I can't for the life of me figure out how to advance the playlist. I can echo commands and pause/stop/mute/quit mplayer from another terminal window, but the key binding to advance to the next song is the page up key... Obviously I can't echo "->" /tmp/fifo
The mplayer documentation doesn't seem to have any solution to this as far as I can tell.
So far I've spent about an hour attempting to figure this out (it seems like it should be trivial, no?) but either my Google-fu is weak or the information isn't out there... I've thought about editing the keybindings of mplayer's Python interface but that seems like a lot of work for something so minor.
Any advice would be appreciated.
I've tried searching the mplayer docs and online. I was expecting a method to advance the playlist using a named pipe that didn't require a special character.
Upvotes: 1
Views: 66
Reputation: 29
Answering this in case it helps anyone else:
So it turns out that it's not as complicated as I was making it. Mplayer expects special keys (arrow keys, etc) when it's running in "normal" mode--for want of a better word--but when it's is running in slave mode, the commands are all "words" of normal characters. So you can echo "pt_step +1" >> tmp/fifo
and get it to advance to the next item in the playlist, rather than having to send a special character to stdin.
In my Python script, I just set the value of a variable command
to echo "**value**" >> tmp/fifo
and used os.system(command)
to write to the pipe.
Upvotes: 1
Reputation: 110561
Page Up, Page Down, arrow keys and a few other have key codes that are composed by escape sequences - and IIRC, will even change depending on the terminal mode you are on.
I have the proper codes listed on the source code of a project of mine (terminedia) - you can check them here - https://github.com/jsbueno/terminedia/blob/5f1dfec7204715a29008543cb26bb9414be5f257/terminedia/input.py#L47 - I'd say that injecting these codes on MPlayer's stdin, the special keys should just work.
(If you are, like it seems, creating a Text User Interface for Mplayer from a terminal, you might want to take terminedia for a tour: for one, you can read the keyboard and mouse events in real time)
Upvotes: 0