Tuesday, 5 April 2011

How To Setup Music Player Daemon With PulseAudio On Ubuntu 10.0.4





















I've been wanting to get Music Player Daemon aka MPD working in Linux for a long time but never got round to it, but today I got it working properly with PulseAudio! The main reason I like MPD is it's actually gapless unlike most other Linux media players (I'm looking at you Rhythmbox, Banshee, and other Gstreamer based players). Also you can fully control MPD from over a LAN via other MPD clients, even from a mobile phone.

Setting Up MPD

With a lot of Googling, I've found a lot of different tutorials on getting MPD to work in Ubuntu. It seems on a desktop PC it's easier to setup MPD as a user service rather than a system service. i could not get it working at all as a system service. I based my setup mainly on this tutorial and updated it for 10.0.4 / Lucid and modified it to fix problems with PulseAudio. This should also work in 10.10 and higher too. Although you can do some things with graphical installers, apps etc, it is far easier to write down commands to copy and paste into a terminal.


First install MPD:

sudo apt-get install mpd


Disable MPD from starting as a system service:

sudo /etc/init.d/mpd stop

sudo update-rc.d mpd disable


Extract and copy the default config file:

gunzip -c /usr/share/doc/mpd/examples/mpd.conf.gz > ~/.mpdconf


Edit the config file:

gedit ~/.mpdconf

Change all paths to point to: ~/.mpd. You need to change the following entries:

music_directory
playlist_directory
db_file
log_file
error_file
pid_file
state_file


Audio setup

At this point I needed to adjust the audio config and modify it slightly from that tutorial to make it work with PulseAudio, (I found the right config for Pulse output here). Find the audio_output section and comment out the alsa section (which is first up in that section) then add:


audio_output {
type "pulse"
name "My Pulse Output"
#server "localhost" # optional
#sink "alsa_output" # optional
}


Make MPD start at login:

In a terminal do:

sudo nano ~/.config/autostart/mpd.desktop
and paste this into it:

[Desktop Entry]

Encoding=UTF-8

Version=0.9.4

Type=Application

Name=Music Player Daemon

Comment=

Exec=mpd

StartupNotify=false

Terminal=false

Hidden=false

Then Ctrl+O to save it and Ctrl+X to exit. Now it should start upon login


Modifications:

I also changed 'user' to my Ubuntu username and I've also enabled (uncomment the relevant lines) zeroconf, replaygain and volume normalization. And also it wouldn't bind to localhost so I changed bind_to_address "any".

And here is my resultant MPD config file (gzipped for convenience). now run MPD by typing 'mpd' into a terminal. If it shows no errors and then disappears (it runs in the background) then all is well.


Finding and playing music:

Next you need to add your music directory, I found it was best to create a link (right click your music folder, select 'create link') and move the link into /home/username/.mpd/music

Now we need an MPD client, Ario and Gnome Music Player Client both run fine in Gnome but there are plenty of choices. Next we need to update the database, in Ario do File, Update Database and we're done. Most of the players I've found so far use an Artist / Album / Title setup which is handy for playing single albums, but I am searching for an easy way of just dumping the entire collection into one playlist and whacking it on random. I've tried using the file system browser in Ario but when I try to dump all the tracks into the playlist it only seems to find less than half my collection. Update: I've discovered that MPD is quite picky about tags so it's apparently best to use EasyTag on your collection which automatically corrects broken tags. Since I have quite a it of music, this may take awhile! Next thing I want to get working is streaming music over the network!


NOTE

Confusingly the MPD wiki states:

"mpd.conf
is the configuration file for mpd(1). If not specified on the command line, MPD first searches for it at ~/.mpdconf then at ~/.mpd/mpd.conf and then in /etc/mpd.conf."


Update: you may need to do "chmod g+X /path-to-music" on your music collection to give it the right permissions.

Update2:  I'm still having trouble with MPD seeing only part of my collection


3 comments:

Numb said...
This comment has been removed by a blog administrator.
Bloomer said...

I spent ages trying to get mpd to work, after looking through this here i got it to work bang on. Thanks a million mate!

Carl Draper said...

Thanks! It took me awhile to get it working so I thought I'd posts it for others and remind myself how it's done :)