How to Control mp3blaster Remotely with Screen

You can talk about anything here, not necessarily game-related. You may also advertise here.
Post Reply
User avatar
The Beatles
Fear me for I am root
Posts: 6285
Joined: Tue May 24, 2005 8:12 pm

Post by The Beatles »

You may have heard of the program mp3blaster, which is a handy and useful program for playing mp3s.
I usually run it inside of GNU screen, so even if I log out of KDE, or have to restart X, whatever, it's still running with the same state.
One annoyance I found was that, suppose I am on the phone or talked to, and need to pause it quickly, the procedure is more tiresome than with a graphical player such as amaroK. With those, I'd just right-click the tray icon and hit Pause. With screen, I would have to switch to the window with a sequence of Ctrl-Lefts or Ctrl-Rights, then hit 5. Not optimal.
However, screen is a powerful and versatile program, so a solution was forthcoming. Screen can remotely paste characters from buffers into any window, so all I needed to do was add some lines to my .screenrc file:

code: Select all

# Mp3blaster-specific commands:
register        P               5               # Play/Pause
register        V               4               # Previous
register        N               6               # Next
register        B               1               # Jump Back
register        F               3               # Jump Forward
register        S               2               # Stop
# These can be sent e.g. via
#       screen -p "~ mp3blaster" -X paste <key>
and also some corresponding commands to my .profile:

code: Select all

# mp3blaster-specific
alias 3p='screen -p "~ mp3blaster" -X paste P'
alias 3v='screen -p "~ mp3blaster" -X paste V'
alias 3n='screen -p "~ mp3blaster" -X paste N'
alias 3b='screen -p "~ mp3blaster" -X paste B'
alias 3f='screen -p "~ mp3blaster" -X paste F'
alias 3s='screen -p "~ mp3blaster" -X paste S'
So now, to pause, all I need to type at the console would be: 3p. Much more optimal. I can even hook that up to KDE keybindings and make them execute the pause command.

This even works if mp3blaster is not the window in the foreground, and it works just as expected, doesn't raise the window, just sends the message. Note that in my .zshrc, I set zsh up so that it would set the title of active windows to the working directory followed by the program name, so the window title is "~ mp3blaster" in my case, but it might be different for you. In that case, just modify the entries in your .profile to reflect this.

I'm a happy camper. :)


[edit] Just to clarify: the numbers in the .screenrc file correspond to the characters to control mp3blaster. So pressing 5 in mp3blaster would pause the song playing.
:wq
Post Reply
  • Members connected in real time

    🔒 Close the panel of connected members