Music Player Daemon/Tips and tricks
Contents
Tips and Tricks
Organizing
MPD doesn't provide a tool to preserve the file structure of your audio files. Check out beets.
Last.fm scrobbling
To scrobble your songs to Last.fm when using MPD, there are several possibilities.
mpdscribble
mpdscribble is a daemon, available in the "community" repository (if you prefer, the "git" version is available in the AUR). This is arguably the best alternative, because it's the semi-official MPD scrobbler and uses the new "idle" feature in MPD for more accurate scrobbling. Also, you do not need root access to configure it, because it doesn't need any changes to /etc
at all. Visit the official website for more information.
After you have installed mpdscribble, do the following (not as root):
$ mkdir ~/.mpdscribble
- Create the file
~/.mpdscribble/mpdscribble.conf
and add the following:
~/.mpdscribble/mpdscribble.conf
[mpdscribble] host = <your mpd host> # optional, defaults to $MPD_HOST or localhost port = <your mpd port> # optional, defaults to $MPD_PORT or 6600 log = /home/<YOUR_USERNAME>/.mpdscribble/mpdscribble.log verbose = 2 sleep = 1 musicdir = <your music directory> proxy = <your proxy> # optional, e. g. http://your.proxy:8080, defaults to none [last.fm] # last.fm section, comment if you do not use last.fm url = http://post.audioscrobbler.com/ username = <your last.fm username> password = <your last.fm password> journal = /home/<YOUR_USERNAME>/.mpdscribble/lastfm.journal [libre.fm] # libre.fm section, comment if you do not use libre.fm url = http://turtle.libre.fm/ username = <your libre.fm username> password = <your libre.fm password> journal = /home/<YOUR_USERNAME>/.mpdscribble/librefm.journal
Please note that passwords can also be written down as MD5:
echo -n 'PASSWORD' | md5sum | cut -f 1 -d " "
- Add
mpdscribble
to the file in which you startmpd
as well (e.g.~/.xinitrc
):
pidof mpdscribble >& /dev/null if [ $? -ne 0 ]; then mpdscribble & fi
Sonata & Ario
Sonata has built-in support for scrobbling, although that requires the program to run the whole time. Additionally, Sonata doesn't cache the songs if they cannot be forwarded to Last.fm at the time of playing, meaning they will not be added to the statistics.
lastfmsubmitd
The daemon lastfmsubmitd is a daemon which may be installed from the "community" repository as well. To install it, first edit /etc/lastfmsubmitd.conf
to reflect your requirements and add both lastfmsubmitd
and lastmp
to the DAEMONS
array in /etc/rc.conf
.
Last.fm playback
Native Last.fm playback
Since version 0.16 mpd has a very well working method to play back last.fm streams.
/etc/mpd.conf
$ playlist_plugin { name "lastfm" user "my_username" password "my_password" }
Then use e.g. mpc to load streams
$ mpc load "lastfm://artist/Beatles"
Never play on start
This feature has recently been added to mpd git by Martin Kellerman, see commits b57330cf75bcb339e3f268f1019c63e40d305145
and 2fb40fe728ac07574808c40034fc0f3d2254d49d
. As of September 2011, this feature has not yet arrived in a mpd version in the official repositories. If support for this feature is still required, have a look at the following proposals.
Installing mpd from the AUR
This is the best method currently available, but is only currently (as of April 2011) enabled in the git version. Install mpd-git from the AUR and add restore_paused "yes"
to your mpd.conf
file.
If you have issues with connecting your client to mpd-git, see Music Player Daemon#Other issues when attempting to connect to mpd with a client.
Method 1
If you do not want MPD to always play on your system start, but yet you want to preserve the other state information, add the following lines to your /etc/rc.d/mpd
file:
Method 1.1
Simpler, working method (disables playing on startup of mpd daemon):
start)
...
mpc -q pause #add this line only add_daemon mpd stat_done
To prevent updates from destroying these modifications, add this file to the NoUpgrade
variable in /etc/pacman.conf
:
NoUpgrade = etc/rc.d/mpd
Method 2
Another simpler method, would be to add mpd to your rc.conf
daemons array and add mpc stop
or mpc pause
to /etc/rc.local.shutdown
and to /etc/rc.local
. (Remember you must have mpc installed to use this method).
Adding only the order in /etc/rc.local
cannot assure that mpd will play absolutely nothing, since there may be a delay before the stop command is executed.
On the other hand, if you only add the order to /etc/rc.local.shutdown
, that will assure that mpd won't play at all, as long as you properly shutdown your system.
Even though they are redundant, adding it to /etc/rc.local
would serve as a safety for those, presumably, rare occasions when you do not shutdown the system properly.
Method 3
The general idea is to ask mpd to pause music when the user logs out, so that mpd will stick to the "pause" state after a reboot. Sending such command can be achieved using mpc, the command line interface to MPD.
GDM users can then add /usr/bin/mpc pause
to /etc/gdm/PostSession/Default
(be sure to add it before exit 0
):
Non-GDM users can use their own login manager's method to launch the line at logout.
Example configuration: Output with 44.1 KHz at e. g. 16 bit depth, multiple programs at once
Why these formats? Because they are standard CDA, because ALSA on its own allows more than one program "to sound" only with dmix — whose resampling algorithm is inferior — and because dmix by default resamples anything lower to 48 KHz (or whatever higher format is playing at the time). Also, some get clicking sounds if at least mpd.conf
is not changed this way.
What's the downside? These settings cause everything (if necessary) to be resampled to this format, such as material from DVD or TV which usually is at 48 KHz. But there is no known way to have ALSA dynamically change the format, and particularly if you listen to far more CDs than anything else the occasional 48 → 44.1 isn't too great a loss.
The following assumes that there are not already other settings which conflict resp. overwrite it. This applies especially to the current user's potential ~/.asoundrc
— which MPD as its own user ignores, therefore the following should go to /etc/asound.conf
:
/etc/asound.conf
defaults.pcm.dmix.rate 44100 # Force 44.1 KHz defaults.pcm.dmix.format S16_LE # Force 16 bits
/etc/mpd.conf
audio_output { type "alsa" # Use the ALSA output plugin. name "HDA Intel" # Can be called anything or nothing tmk, but must be present. options "dev=dmixer" device "plug:dmix" # Both lines cause MPD to output to dmix. format "44100:16:2" # the actual format auto_resample "no" # This bypasses ALSA's own algorithms, which generally are inferior. See below how to choose a different one. use_mmap "yes" # Minor speed improvement, should work with all modern cards. } samplerate_converter "0" # MPD's best, most CPU intensive algorithm. See 'man mpd.conf' for others — for anything other than the poorest "internal", libsamplerate must be installed.
If one wants to leave the bit depth decision to ALSA resp. MPD, comment out resp. omit the dmix.format line and change the one for mpd with format to "44100:*:2".
Control MPD with lirc
There are already some clients designed for communications between lircd and MPD, however, as far as the practical use, they aren't very useful since their functions are limited.
It's recommended to use mpc with irexec. mpc is a command line player which only sends the command to MPD and exits immediately, which is perfect for irexec, the command runner included in lirc. What irexec does is that it runs a specified command once received a remote control button.
First of all, please setup your remotes as referred to the Lirc article.
Edit your favored lirc startup configuration file, default location is ~/.lircrc
.
Fill the file with the following pattern:
begin prog = irexec button = <button_name> config = <command_to_run> repeat = <0 or 1> end
An useful example:
## irexec begin prog = irexec button = play_pause config = mpc toggle repeat = 0 end begin prog = irexec button = stop config = mpc stop repeat = 0 end begin prog = irexec button = previous config = mpc prev repeat = 0 end begin prog = irexec button = next config = mpc next repeat = 0 end begin prog = irexec button = volup config = mpc volume +2 repeat = 1 end begin prog = irexec button = voldown config = mpc volume -2 repeat = 1 end begin prog = irexec button = pbc config = mpc random repeat = 0 end begin prog = irexec button = pdvd config = mpc update repeat = 0 end begin prog = irexec button = right config = mpc seek +00:00:05 repeat = 0 end begin prog = irexec button = left config = mpc seek -00:00:05 repeat = 0 end begin prog = irexec button = up config = mpc seek +1% repeat = 0 end begin prog = irexec button = down config = mpc seek -1% repeat = 0 end
There are more functions for mpc, run man mpc
for more info.
Control MPD with phone
remuco via bluetooth
- install remuco -- a wireless remote control for several Linux media players (aur)
- transfer remuco client -- jar/jad files from
/usr/share/remuco/client/
to your phone and install it - run
remuco-mpd
(as current user) - run remuco on your phone, define a new bluetooth remuco connection (pair first if you haven't done this previously) and explore its capabilities
others
There are several MPD-specific clients available in the app-store/market of Symbian, Android and iOS.
MPD & PulseAudio
Edit /etc/mpd.conf
, and uncomment the audio_output section for the type "pulse". The server and sink lines of it should be commented unless you know what you're doing.
Then, add the mpd user (and yours if you haven't done so already) to the necessary pulse groups. The pulse-access group should be sufficient but you may want to add pulse-rt as well. The group "pulse" doesn't appear to be necessary.
# gpasswd -a mpd pulse-access # gpasswd -a mpd pulse-rt
Lastly, you may or may not need to copy ~/.pulse-cookie
from your current (pulse working) user's dir to your mpd user's home directory. It is likely to be /var/lib/mpd
if you followed the first part of this wiki. This would probably only allow your current user to listen in on MPD's pulse. You may consider running pulse system-wide if that's insufficient.
Cue Files
To make cue file support actually work, you have to work around a nasty libcue bug. Libcue copied some files directly from libcdio, making it conflict with it. Steps to do to get proper cue support:
- remove
libcdio
temporary (pacman -Rdd libcdio
) - install libcue
- install mpd with ABS or from AUR.
- install
libcdio
again
Version 0.17 will fix this issue, implementing its very own cue parser, which will then also allow parsing cuesheets, that are embedded into the files tags (CUESHEET tag). This will work for most, if not all relevant music files.
HTTP Streaming
Since version 0.15 there is a built-in HTTP streaming daemon/server that comes with MPD. To activate this server simply set it as output device in mpd.conf:
audio_output { type "httpd" name "My HTTP Stream" encoder "vorbis" # optional, vorbis or lame port "8000" # quality "5.0" # do not define if bitrate is defined bitrate "128" # do not define if quality is defined format "44100:16:1" }
Then to listen to this stream simply open the URL of your mpd server (along with the specified port) in your favorite music player. Note: You may have to specify the file format of the stream using an appropriate file extension in the URL. For example, using Winamp 5.5, You would use http://192.168.1.2:8000/mpd.ogg rather than http://192.168.1.2:8000/.
To use mpd to connect to the stream from another computer.
mpc add http://192.168.1.2:8000