Mar 012014
 

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

It is also used for one of the two purposes, as local daemon or as network daemon. MPD don’t use many resources. It is designed to make its job in background playing music from its database.

For connecting with MPD and managing music there are many options and clients. CLI clients, GTK clients, Qt clients and even from VI.



MPD uses flat file databases for maintaining the basic music collection info.
After starting, MPD loads it’s database into RAM and has no need for searching through HDD. Usually the music is saved in ~/Music directory and MPD will check that folder as first when making the database. If you have your music collection in some other folder, add its path in the mpd.conf file, usually located in the directory /etc.

MPD`s client/server nature gives it some advantages over all-round music players. Clients can communicate with MPD not only locally on the same computer, but they can also communicate over network.

In this way you can access and listen to all your music but without the need to have it physically with you. Also it does not require an X server to run or to be installed, it runs fine from console and there are plenty of ncurses based MPD clients. Every user over the network can have it’s own client connected to the MPD server, sharing the same database but every user will listen to his favorite songs.

mpd01

As said, there are many MPD clients, for any taste and they also come for various devices and operating systems. Also Android. With that in mind we could build our own music streamer. If you have some cool hardware like Raspberry Pi, then you’ll have more benefits. But for this simple project every computer connected to Internet will work.

What we need?

1.) working computer with Linux
2.) Internet connection
3.) Android device
4.) Around 45 minutes

Installation

As said, MPD is an open source software and can stream audio to any device connected to the computer and it can also be controlled from any device. For making a music streamer using MPD the first thing that you have to do it’s to install MPD. It is usually available in the main repositories of all the most common distributions.

1.) Debian and Debian derivate

apt-get install mpd mpc

2.) OpenSuse

zypper install mpd mpc

3.) Fedora

yum install mpd mpc

4.) Arch

pacman -S mpd mpc

5.) Gentoo

emerge mpd mpc

Note, mpc is a client for MPD. mpc connects to a MPD and controls it according to commands and arguments passed to it. If no command is given, the current status is printed (same as ‘mpc status’).

Configuration

When you finish the installation of MPD become root, or use sudo, to open with your favorite text editor the file /etc/mpd.conf file for editing.
You should see something similar to this:

music_directory       "/home/user/Music"         # Your music dir.
playlist_directory    "/home/user/.mpd/playlists"
db_file               "/home/user/.mpd/mpd.db"
log_file              "/home/user/.mpd/mpd.log"
pid_file              "/home/user/.mpd/mpd.pid"
state_file            "/home/user/.mpd/mpdstate"
#user                  "user"
audio_output { 
         type                    "alsa"
         name                    "My ALSA Device"
         device                  "hw:0,0"     # optional
         format                  "44100:16:2" # optional
}

audio_output {
         type                    "fifo"
         name                    "my_fifo"
	 path                    "/tmp/mpd.fifo"
	 format                  "44100:16:2"
}

# Binding to address and port causing problems in mpd-0.14.2 best to leave
# commented.
# bind_to_address       "127.0.0.1"
#port

This is default mpd.conf. Change paths to your music collection and path to .mpd folder. Save it, exit and test MPD.
Start it with the command

 /etc/init.d/mpd start

. Before adding it as a default daemon to the system, you need to do some more editing in the mpd.conf file so open it again. In the section bind to address change localhost variable to any and add the http streaming section:

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"
}

Save the changes, restart the daemon and add it to system default daemons, the one that starts at boot.

Selecting a client

Selecting your client depends on your specific needs. If you would like to control music from your laptop or workstation you can use Sonata or ncmpcpp. Sonata is a nice and popular GTK client for MPD while ncmpcpp is one of the most popular ncurses based MPD clients.

sonata client

If you decided to build an simple, small and discrete music server you can use one of the many MPD clients for Android.
Two of the best apps are in my opinion Droid MPD and MPDroid. Both of them are very simple to configure.

MPDroid settings                                                                                                   Droid MPD settings

mpd02

MPDroid settings

When you configure these applications you usually need only to add your IP adress.
Local IP to remote control it at your home and your public IP if you want to stream music everywhere to your Android device.

Playing music

We are now at the end, the only step left is to play, listen and enjoy our music with the new build music server/streamer.
Open your client, choose your favourite song and relax..

Raspberry PI + MPD and MPDroid as client:


Popular Posts:

Flattr this!

  One Response to “Play your Music on Linux with Music Player Daemon”

  1. potrei avere un chiarimento?
    Se non ho capito male, i file musicali risiedono in “/home/user/Music” , come posso fare per includere temporaneamente ad esempio i files musicali di una chiavetta usb che inserisco nel pc dove risiede mpd, e selezionarli sul client, senza spostarli in music?

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

*