MPD (or Music Player Daemon) is an audio player designed to run as a system service (hence the daemon), with a client-server type architecture, which starts together with the computer independently of the graphical interface. What it does is index our music library at an impressive speed and make it available to us so that we can listen to it both from the PC where it is installed, and through the network.
For this there are different clients, which are available not only for Linux, but also for Android, and even for Windows.
Despite being extremely versatile, the relative complexity of its configuration often scares off more than one person. Today I'm going to explain how to prevent MPD from running as a service and instead start it when we log in with our user's privileges. In this way we avoid an unnecessary security risk (more than one paranoid person will thank me for it ).
After following many guides and reneging more than once to configure it, I took on the task of creating a script to facilitate the configuration of this great program so that it is a little more user-friendly: here it is.
To start, we must install MPD and to control it through a graphical interface we will use Sonata:
sudo aptitude install mpd sonata
Then we stop the service and prevent it from starting as a system daemon:
sudo service mpd stop
sudo update-rc.d mpd disable
And now if we will go to the application configuration, and here I must make another clarification: the script creates a basic configuration file with the parameters just and necessary for it to work, but for the guide we will use the configuration file that MPD creates by default , which is duly commented and has many more options that may or may not be useful, so I recommend that you at least look at it.
We create the necessary directories for MPD:
mkdir -p ~ / .mpd / playlists
We copy the configuration file to the newly created folder and create the files we need:
gunzip -c /usr/share/doc/mpd/examples/mpd.conf.gz> ~ / .mpd / mpd.conf
touch ~ / .mpd / mpd.db
touch ~ / .mpd / mpd.log
touch ~ / .mpd / mpd.pid
touch ~ / .mpd / mpdstate
And now we begin to edit the configuration file itself (I use medit, you use the one you are used to):
medit ~ / .mpd / mpd.conf
First we must tell it where our music is located and the path where the files we just created are:
music_directory "~ / Music"
playlist_directory "~ / .mpd / playlists"
db_file "~ / .mpd / mpd.db"
log_file "~ / .mpd / mpd.log"
pid_file "~ / .mpd / mpd.pid"
state_file "~ / .mpd / mpdstate"
We comment on the user and group options (adding # at the beginning of the line). They are not necessary since MPD will run with the privileges of the user who starts it.
Where it says "For network" we have two options: if we are simply going to use MPD as if it were any other music player, where it says "bind_to_address" we simply put "localhost". If instead we are going to control MPD from another device (for example, an Android Smartphone, as we will explain later) or we want to stream audio, instead of localhost we will place (always in quotes) our IP address, for example:
bind_to_address "192.168.1.10"
Where it says "port" we change the one that comes by default (6600) for some other (in this case 8888) since I have read out there that the default sometimes gives problems, and it should look like this:
port «8888»
Then I suggest you uncomment the following lines, to improve the experience (although it depends on each one):
gapless_mp3_playback "yes"
metadata_to_use «artist, album, title, track, name, genre, date, composer, performer, disc»
auto_update "yes"
Then we go to the audio configuration, where it says "Audio Input" we leave it as it is, and where it says "Audio Output" depending on whether we use ALSA or PulseAudio we uncomment the corresponding section. For example if we use ALSA:
audio_output {
alsa
name “My ALSA Device”}
And if we use Pulse:
audio_output {
type «press»
name "My MPD PulseAudio Output"}
If we want to listen to our music from another PC or even from our phone (as long as we are on the same local network) we can activate the http server included by default in MPD, for this we only have to uncomment the following lines:
audio_output {
type "httpd"
name "My HTTP Stream"
"vorbis" encoder # 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"
}
To connect (in theory, since this I did not have the opportunity to test it) we only have to enter the IP of our server followed by the specified port number, for example: 192.168.1.10:8000, although to play the music stream in some players we must add the following to the end "/mpd.ogg" and we would have something like this:
192.168.1.10:8000/mpd.ogg
We are almost done, I only recommend that you uncomment the following lines:
mixer_type «software» #So that when adjusting the music volume it does not affect the overall volume of the system
replaygain «track»
filesystem_charset "UTF-8"
id3v1_encoding "UTF-8"
Ready, we save the file and close the editor. Now from the console we execute "mpd" so that it starts working, and we open Sonata to configure it. We right-click anywhere in the program and choose "Preferences ..." and then MPD. There we will complete as follows:
Name: we can put what we want.
Server: Localhost or our IP (it depends on what we have put in the configuration file)
Port: 8888 (or whatever we have put in the configuration file)
and we mark the box that says "Automatically connect at startup", we click "OK" and they should be able to see their files in the "library" tab (it depends on the amount of Music they have, it may take a couple of minutes).
We can add "mpd" to the login so as not to have to start it manually every time, in XFCE we do it from: "Menu" -> "Configuration manager" -> "Session and start" -> "Auto start applications" -> "Add":
And now, I'm going to show you how you can control your music player in a very simple way from your Android, for that we only need a small application called MPDroid (I owe you the link, but you can find it in the application store).
We configure it as follows: we go to «Settings» -> «Connection Settings» -> «Default Connection Settings» -> and there we complete it as follows:
Host: 192.168.1.10 (the address of our MPD server)
Port: 8888 (the port we assign to MPD)
Streamming host: 192.168.1.10 (the same address as our MPD server)
Streamming Port: 8000 (is the default address)