Mpd, ncmpc++ and keybindings for playback control
I already mentioned that mpd & ncmpc++ is a great music player. I imagine a console music player can be a little discouraging and realized the other day that major desktop environments like Gnome don’t have built-in support for music playback control through mpd. If you assign a key to play/pause and next/previous song in the Gnome control center, it will work in a lot of popular music players like banshee, amarok, exaile and so on but not with mpd. When you finally convinced yourself to use mpd, this could be another setback.
The “problem” however can be easily solved. It’s as easy as
- figuring out the commands to play, pause and switch songs in mpd
- assigning this command to a key
For both steps exist several solutions of which I will explain one.
Figuring out the commands
You can’t control the playback of songs directly with mpd. You will have to do it with the frontend you are using. In my case that’s ncmpcpp but any other frontend such as mpc or ncmpc will do. Each action can be supplied as an argument for the ncmpcpp command:
- playback/pause: ncmpcpp toggle
- previous song: ncmpcpp prev
- next song: ncmpcppp next
- stop: ncmpcpp stop
Assigning keys to the commands
I believe all desktop environments/window managers provide a way to assign keys to predefined and custom actions. The predefined actions in Gnome are easily accessible through the Gnome control center (Alt + F2 gnome-control-center). As mentioned earlier, the predefined actions for music playback don’t’ work with mpd. We will have to create custom actions.
The custom actions in Gnome are well hidden in gconf-editor. Press Alt + F2 and type gconf-editor to open it. Navigate to /app/metacity/keybinding_commands and fill in the commands we found earlier. Afterwards you can assign a key to each command in /app/metacity/global_keybindings. Key modifiers like Ctrl and Alt are <Control> and <Alt> respectively. I, for example, added ncmpcpp next to command_1 and assigned <Control>Left (Left is the left arow key) to run_command_1.
Thanks! I had installed mpc, and then totally forgotten I had it (since I was using ario (gtk frontend)). These commands work perfectly for me!
I’m happy you were able to project these ncmpcpp commands to mpc. Most people don’t realize how powerful some well placed commands / shortcuts can be for a user.