How to Install and setup mpd + mpdscribble + ncmpcpp

Tips and Tricks (or the joys of mpd)

In these replies to the tutorial, I'll be adding a few bits and pieces of information to help you get the most of the mpd daemon and ncmpcpp.

Control ncmpcpp playback with your keyboard media keys

One of the first things that may catch some users off guard is the fact that once they start using the mpd daemon with any of the console players (like ncmpcpp), their keyboard media keys do not work. ncmpcpp bindings configuration file does not understand these keys or their key codes, either. And neither it offers any command line options to control playback that we could bind to the Keyboard Shortcuts application that comes with most Desktop Environment like MATE.

Seems hopeless, but it is not.

1. Install mpc (Music Player Client), the companion player to mpd

mpc is a command line-only client to the mpd daemon. It can control all aspects of music playback and it is ideal for our purposes. It's small, simple and fast.

ncmpcpp gets all its playback information from to the mpd daemon. So, if we tell mpd to start playing a song with a command like mpc play, ncmpcpp will be informed too and update itself accordingly. It's a beautiful combination between mpd, mpc and ncmpcpp. And its is one of the reasons why music daemons are so great.

$ sudo apt-get install mpc

###2. Get to know the mpc playback commands
If you read mpc documentation (man mpc), you'll get all information you need to learn how to control music playback. But here are the relevant mpc commands we will be using:

  • mpc toggle (start playback if stopped or pause, and pause playback if playing)
  • mpc stop (stop playback)
  • mpc next (move to next song in playlist)
  • mpc prev (move to previous song in playlist)
  • mpc volume (increase or decrease volume)

###3. Get to know your keyboard media keys name
Your keyboard media keys have special names under X. The ones we are interested in, on the same order as the above list are:

  • XF86AudioPlay
  • XF86AudioStop
  • XF86AudioNext
  • XF86AudioPrev
  • XF86AudioRaiseVolume and XF86AudioLowerVolume

###4. Set your keyboard shortcuts
I think you already see where this is going and the rest of this tip is just using space. But nonetheless I'll go through the needed steps to configure your keyboard shortcuts

4.1. Start the Keyboard Shortcuts application
First you want to open the Keyboard Shortcuts window. You get to it through the Ubuntu-MATE panel menu at System -> Preferences -> Hardware -> Keyboard Shortcuts

In the window that opens you may already see the above keys configured to some other application; usually vlc or some other GUI music client.

The next operation will remove your default media keys configuration from the Keyboards Shortcuts and assign them to a new client. It's the price you pay; Ubuntu-MATE Keyboard Shortcuts doesn't allow you to assign the same key to different applications. So, if you don't want this to happen, stop now. But who needs another music client when you already have the best one in the whole world, ncmpcpp? If you agree, press on!

4.1. Add a new action
You just need to click the '+Add' button to add a new action that will be inserted to the end of the list under the Custom Shortcuts dropdown.

On the "name" field type something meaningful, like "MPD play/pause", or "MPD Toggle".
On the "command" field type the actual command to be issued. On this case, mpc toggle

4.3. Add the shortcut
Once you apply, the action will be added to your custom shortcuts list and you just need to now assign it a new shortcut.

This is as simple as clicking your new action under the Shortcut column. You'll see the text changes to New Shortcut.... Now hit the Play/Pause media key on your keyboard. And voilá!

4.4 The Volume shortcuts
The actual mpc command to control music volume is:

mpc volume +|- value

Volume in mpd is measured as a percentage, from 0% (total silence) to 100% (maximum volume). So a command like mpc volume +2 will increase the volume by 2%, while mpc volume -3 will decrease it by 3%. I have my own volume key shortcuts set to +2 and - 2.

That's it.

I trust you will not have any problems setting the rest of your keyboard configurations for music playback. Enjoy!

2 Likes