Mpd

From ArchWiki

(Redirected from MPD - Music Player Daemon)
Jump to: navigation, search
i18n
English
Polski
Nederlands
Русский
简体中文

Contents

[edit] What is mpd?

mpd (Music Player Daemon) is an audio player that has a server-client architecture. mpd runs in the background as a daemon, manages playlists and a music database, and uses very few resources. In order to interface with it, you need a separate client. More information can be found on their website

[edit] Daemon Install Procedure

Sync and install with pacman:

# pacman -S mpd

[edit] Configure mpd

For more information about mpd configuration visit http://mpd.wikia.com/wiki/Configuration

[edit] Quick Single User Installation

  • As root, create and edit /etc/mpd.conf (If it already exists delete it first, this is safe.)
# rm /etc/mpd.conf
# $EDITOR /etc/mpd.conf

Never put this file in the user's directory like some tutorials suggest. This would complicate things and most of the time doing this is useless (notice you're reading a quick installation howto). If you previously created a .mpdconf file in your home, remove it now. This is important to prevent conflicts. When placing it in /etc, like we do here, mpd will be able to run as a daemon at boot. Otherwise, a script would be needed to run mpd AFTER the user has logged (like kdm or ~/.fluxbox/startup) or it would require a manual move each time. For a single music collection, the method used here is simply better, even while the collection is shared to multiple users. Also, don't be afraid about root privileges: even while mpd runs as a daemon, it never completely runs as root since it automatically drops its root privileges after execution.

To make audio output actually work ensure that you have setup audio card and mixer correctly. See ALSA. Do not forget to unmute the required channels in alsamixer, raise the volume and save changes with alsactl store. See ~/.mpd/error if it still doesn't work.

Make sure your card can do hardware mixing (most of them can, including onboard audio). Or else this could cause problems with multiple sound playback. For example, this can prevent Mplayer from playing back sound while the mpd daemon is running, returning an audio error message stating the device is busy.


  • In /etc/mpd.conf add the lines
 music_directory       "~/Music"
 playlist_directory    "~/Playlists"
 db_file               "~/.mpd/db"
 log_file              "~/.mpd/log"
 error_file            "~/.mpd/error"
 pid_file              "~/.mpd/mpd.pid"
 state_file            "~/.mpd/mpdstate"
 user                  "mpd"
 bind_to_address       "127.0.0.1"
 port                  "6600"
 #connection_timeout   "60"
 #max_playlist_length  "16384"
 #filesystem_charset   "ISO-8859-1"
 #id3v1_encoding       "ISO-8859-1"

These are the most common lines. You shouldn't need anything else. See the file /etc/mpd.conf.example for more specific options.

  • Look at the line starting with user and replace mpd with your username. Save changes and exit the editor.
  • Now exit the root mode and log as the normal user (the same you specified in mpd.conf).
  • Create the new directories
$ mkdir ~/Music
$ mkdir ~/Playlists
$ mkdir ~/.mpd
  • Copy your music in ~/Music (or else specify your music folder correctly in mpd.conf):
$ cp -r /media/sda5/music_collection ~/Music
  • Create the pid file
$ touch ~/.mpd/mpd.pid
  • Create the mpd database (This can take a while depending on the size of your collection.):
$ mpd --create-db
  • Start mpd:
$ mpd
  • Edit /etc/rc.conf and add mpd to the list of daemons to start on bootup.
  • To test it out, install a very small client called mpc
# pacman -S mpc        (as root)
$ mpc ls |  mpc  add   (as user)
$ mpc play

[edit] Troubleshooting

Note: in case of permission problems when using ESD with mpd run this as root:

# chsh -s /bin/true mpd

[edit] Tips

To get rid of timeouts (i.e. when you paused music for long time) in gpmc and other clients uncomment and increase connection_timeout option in mpd.conf.

If files and/or titles are shown in wrong encoding, uncomment and change filesystem_charset and id3v1_encoding options. Note that you cannot set encoding for ID3 v2 tags. To workaround this you may use external tag readers.

If you want to use another computer to control mpd over a network, the bind_to_address option in mpd.conf will need to be set to either your IP address, or any if your IP address changes frequently. Remember to add mpd to the /etc/hosts.allow file to enable external access.

[edit] Client Install Procedure

Install a client program for mpd. Popular options are:


Install with:

# pacman -Sy mpc
# pacman -Sy ncmpc
# pacman -Sy sonata
# pacman -Sy gmpc

[edit] Extra stuff

[edit] Last.fm scrobbling

To scrobble your songs to Last.fm using MPD there are several alternatives. The easiest way, if you don't care about having to have a program window open all the time, is using Sonata which is a graphical frontend to MPD. It has built-in support for Last.fm scrobbling in its preferences.

If you're not too keen on using Sonata (and having it open at all times) there is the very popular mpdscribble which acts as a background process which continuously fetches information about the status of MPD and quietly submits the information to Last.fm. It's fairly easy to configure and also easy to monitor using /var/log/mpdscribble.log.

[edit] Never play on start

If you don't 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:

   ...
   stat_busy "Starting Music Player Daemon"
   # always start in paused state
   awk '/^state_file[ \t]+"[^"]+"$/ {
       match($0, "\".+\"")
       sfile = substr($0, RSTART + 1, RLENGTH - 2)
   } /^user[ \t]+"[^"]+"$/ {
       match($0, "\".+\"")
       user = substr($0, RSTART + 1, RLENGTH - 2)
   } END {
       if (sfile == "")
               exit;
       if (user != "")
               sub(/^~/, "/home/" user, sfile)
       system("sed -i \x27s|^\\(state:[ \\t]\\{1,\\}\\)play$|\\1pause|\x27 \x27" sfile "\x27")
   }' /etc/mpd.conf
   /usr/bin/mpd /etc/mpd.conf &> /dev/null
   ...

This will change the player status to "paused", if it was stopped while playing. Next, you want this file to be preserved, so mpd updates won't erase this edit. Add (or edit) this line to your /etc/pacman.conf:

NoUpgrade = etc/rc.d/mpd

[edit] MPD & Alsa

Sometimes, when you use other audio output, e.g: some web pages containing Flash applets, mpd cannot reproduce anything anymore (until you restart). The error looks something like: (if you search the file /var/log/mpd/mpd.error)

Error opening alsa device "hw:0,0": Device or resource busy

And here is the solution (dmix saving our life again). Apply these lines in your /etc/mpd.conf:

audio_output {
        type                    "alsa"
        name                    "Sound Card"
        options                 "dev=dmixer"
        device                  "plug:dmix"
}

And then restart with /etc/rc.d/mpd restart

Searching on Internet I found the reason for why that happens in Gentoo's wiki:

  • The sound card does not support hardware mixing (uses dmix plugin)
  • An application does not work with ALSA with it's default settings

[edit] External links

Personal tools