Saturday, August 16, 2008

HowTo: Musicpd (Music Player Daemon) on FreeBSD

MPD stands for Music Player Daemon. It is made to control music through a very unique way. MPD has support for MP3, Ogg, FLAC, AAC, Mod, and wav files.

Let's proceed with the steps needed to install musicpd from ports:
  • % su
  • # cd /usr/ports/audio/musicpd ; make install clean
  • if you want select additional audio formats such as AAC and MOD files
Now let's move onto the configuration by copying the port's supplied example and editing from there:
  • # cp /usr/local/share/doc/mpd/mpdconf.example /usr/local/etc/mpd.conf
  • # chmod 644 /usr/local/etc/mpd.conf
  • # vi /usr/local/etc/mpd.conf
music_directory "/mnt/music"
playlist_directory "~/playlists"
db_file "~/database"
log_file "~/log"
error_file "~/error"
pid_file "~/pid"
state_file "~/state"
user "musicpd"

port "6600"
bind_to_address "127.0.0.1"

audio_output {
type "oss"
name "OSS"
}
To prevent MPD running as root we can setup a new user (musicpd):
  • # adduser
Username: musicpd
Full name: Music Player Daemon
Uid (Leave empty for default):
Login group [musicpd]:
Login group is musicpd. Invite mpd into other groups? []:
Login class [default]: daemon
Shell (sh csh tcsh bash rbash nologin) [sh]: nologin
Home directory [/home/musicpd]:
Use password-based authentication? [yes]: no
Lock out the account after creation? [no]: yes
Username : musicpd
Password :
Full Name : Music Player Daemon
Uid : 1002
Class : daemon
Groups : musicpd
Home : /home/musicpd
Shell : /usr/sbin/nologin
Locked : yes
OK? (yes/no): yes
Add another user? (yes/no): no
Goodbye!
  • # mkdir -p /home/musicpd/playlists
  • # chown muiscpd:musicpd /home/musicpd/playlists
To start MPD at boot time:
  • # echo 'musicpd_enable="YES"' >> /etc/rc.conf
Finally we start MPD and create the database:
  • # /usr/local/bin/mpd --create-db /usr/local/etc/mpd.conf
Now that we have the daemon up and running we need to put it to good use. I use the NCMPC client for the job.

To install NCMPC from ports:
  • # cd /usr/ports/audio/ncmpc ; make install clean

11 comments:

Anonymous said...

Awesome! Thank you so much, this worked. I've always been trying to make musicpd (mpd) work on FreeBSD. And now does.

tangram said...

:)

Thanks for the positive feedback.

Anonymous said...

mpd is now named musicpd on ports, and in general the binary is musicpd, do you know why? Just asking because am a bit confused seeing you are running it as mpd

tangram said...

I'm not sure I follow...

In the Linux world Music player Daemon is known by its acronym MPD thus the application is named mp in all distribution repositories.

In the FreeBSD side of things there is a mpd in the base system in FreeBSD 9. To distinguish both the ports team opted to name it musicpd in the ports tree.

In short, mpd (Linux) = musicpd (FreeBSD).

Anonymous said...

thank you for the quick reply. :)

Anonymous said...

Nice job!
M(usic)PD is so light & fast so I love it ;)
A time ago got it on my ubuntu - now ill try it with a BSD

Thanks.

tangram said...

Thanks for the feedback :)

Though this howto is a few years old it should largely (if not completely) apply.

Unknown said...

create-db
is deprecated, how should i create the database file now?

tangram said...

Matthew,

This how-to was created in 2008, roughly 7 years ago and I'm sure MPD changed much since.

I don't use MPD these days so I'd suggest having a look at the manpage or using a search engine.

Regards,
tangram.

Anonymous said...

Hi Tangram.

May I just ask, if you don't use MPD anymore, what then do you use as its replacement? I ask because I'm evaluating the use of 'xmms2d', and so far, MPD seems a nicer, cleaner option.

Best,
Paul Kotschy

tangram said...

TBH nothing :) I hardly listen to music these days -.-