MPD

From Gentoo Wiki
Jump to: navigation, search

MPD (Music Player Daemon) is a flexible, server-side application for playing music. Through plugins and libraries it can play a variety of sound files while being controlled by a network protocol.

Installation

USE flags

Cannot load package information. Is the atom media-sound/mpd correct?

Note
A number of these flags are set by the desktop profile.

Emerge

root #emerge --ask media-sound/mpd

Configuration

After finished installation MPD should be working with the Gentoo shipped default configuration.

A list of supported plugins/features of your MPD can be obtained by running:

user $mpd --version

Basic configuration

Below an example of a simple configuration:

FILE /etc/mpd.conf
music_directory      "/var/lib/mpd/music"
playlist_directory   "/var/lib/mpd/playlists"
db_file              "/var/lib/mpd/database"
log_file             "/var/lib/mpd/log"
state_file           "/var/lib/mpd/state"

user                 "mpd"

bind_to_address      "localhost"
bind_to_address      "/var/lib/mpd/socket"

input {
        plugin "curl"
}

At this point MPD should be able to run as a system daemon with its own user called mpd, which is the default setting of MPD.

Service

OpenRC

To start MPD:

root #rc-service mpd start

To start MPD at boot time, add it the default runlevel:

root #rc-update add mpd default

systemd

To start MPD immediately:

root #systemctl start mpd

To start MPD at boot time:

root #systemctl enable mpd

PulseAudio (optional)

If MPD was build with PulseAudio support (pulseaudio USE flag), add a dedicated audio_output section to your /etc/mpd.conf:

FILE /etc/mpd.conf
audio_output {
        type            "pulse"
        name            "Pulse Output"
        mixer_control   "Master"
}
Note
It may be a good practice to run both PulseAudio and MPD under X11 user instead.

Built-in HTTP streaming server (optional)

If MPD was build with network USE flag, add a dedicated audio_output section to your /etc/mpd.conf:

FILE /etc/mpd.conf
audio_output {    
        type            "httpd"
        name            "HTTP Stream"
        encoder         "vorbis"                # optional, vorbis(OGG) or lame(MP3)
        port            "8000"
        bitrate         "192"                   # do not define if quality is defined      
        format          "44100:16:1"
}

bind_to_address "0.0.0.0"

Replace localhost with 0.0.0.0 or a specific interface IP. Bind to address 0.0.0.0 means here: stream on all local found IP interfaces. You could change it to a specific interface IP address like e.g. 192.168.1.2 then the streaming server is bound to that interface IP only.

Note
Some players require to specify the file format in the URL to be able to connect to the stream. Example: http://192.168.1.2:8000/mpd.ogg

Running as a specific user (optional)

Sometimes it may be handy to run MPD as a specific user.

Start with copying /etc/mpd.conf to ~/.mpdconf. There are some changes that you will have to change in order to run MPD as a user, most importantly user and group, also make sure the various path settings are correct:

FILE ~/.mpdconfuser definition
user    "YOUR_USER"
group   "YOUR_USER"

Make sure your user has read access to the directory you specify in music_directory.

Note
If your cron program supports @reboot you can create a cronjob that has /usr/bin/mpd start at boot in place of the init script.

Bluetooth headset (optional)

Setup a Bluetooth headset first, according to the Bluetooth headset article.

ALSA (non-PulseAudio) setup with BlueZ 5

Put a user level ~/.asoundrc file in MPD's $HOME directory, which is /var/lib/mpd by default. MPD will be able to control the volume of the headset.

FILE /var/lib/mpd/.asoundrc
# Specify the parameters of the Bluetooth connection
defaults.bluealsa {
     interface "hci0"            # host Bluetooth adapter
     device "XX:XX:XX:XX:XX:XX"  # Bluetooth headset MAC address
     profile "a2dp"
}

To be able to switch between the Bluetooth headset and the default sound card, add these lines to the audio_output section in /etc/mpd.conf:

FILE /etc/mpd.conf
audio_output {
        type            "alsa"
        name            "My ALSA Device"
}

audio_output {
        type            "alsa"
        name            "ALSA Bluetooth Headset"
        device          "bluealsa"
        mixer_type    "software"
}

MPD might crash when switching output _while_ playing (if so, pause before switching).

If you experience some issues while trying to play AAC or other files, like:

user $mpd --no-daemon --stderr
...
alsa_output: Failed to open "My ALSA Device" [alsa]: Error opening ALSA device "bluealsa" (snd_pcm_hw_params): Invalid argument
...

Then add this line to your audio_output:

FILE /etc/mpd.conf
        format          "44100:16:2"

ALSA (non-PulseAudio) setup with BlueZ 4 (deprecated)

Put a user level ~/.asoundrc file in MPD's $HOME directory, which is /var/lib/mpd by default. The following example creates an extra "Bluetooth" slider in any mixer application, and enables MPD to control the volume of the headset:

FILE /var/lib/mpd/.asoundrc
# Change device to the MAC address of your headset
pcm.btheadset {
   type plug
   slave {
      pcm {
         type bluetooth
         device "XX:XX:XX:XX:XX:XX"
         profile "auto"
      }
   }
   hint {
      show on
      description "Bluetooth Headset"
   }
}

ctl.btheadset {
   type bluetooth
}

pcm.btheadset_softvol {
   type softvol
   slave.pcm "btheadset"
   control.name "Bluetooth"
   control.card 0
}

# Using bluetooth as default:
#pcm.!default {
#   type plug
#   slave.pcm "btheadset_softvol"
#}

To be able to switch between the Bluetooth headset and the default sound card, add these lines to the audio_output section in /etc/mpd.conf:

FILE /etc/mpd.conf
audio_output {
        type            "alsa"
        name            "My ALSA Device"
}

audio_output {
        type            "alsa"
        name            "ALSA Bluetooth Headset"
        device          "btheadset_softvol"
        mixer_type      "software"
}

MPD might go crazy when switching output _while_ playing, and fill its log (if so, pause before switching).

If you experience some issues while trying to play AAC or other files, like:

user $mpd --no-daemon --stderr
...
alsa_output: Failed to open "My ALSA Device" [alsa]: Error opening ALSA device "bluealsa" (snd_pcm_hw_params): Invalid argument
...

Then add this line to your audio_output:

FILE /etc/mpd.conf
        format          "44100:16:2"

Clients

Commandline/Console

Graphical (GTK+)

Graphical (Qt)

Web

  • ympd — MPD Web GUI - written in C, utilizing Websockets and Bootstrap/JS

Scrobblers

Scrobblers are clients that submit to Audioscrobbler — compatible services (eg. libre.fm or last.fm)

Troubleshooting

For general troubleshooting refer to the MPD user manual troubleshooting section

See also

  • Upmpdcli — a free and open source UPnP media renderer front-end for Music Player Daemon (MPD).

External resources