Music Player Daemon: simple setup (and some extra uses)

Music Player Daemon + Sonata

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 tends to scare more than one. Today I am going to explain to you how to prevent MPD from running as a service and instead starting when we log in with the privileges of our user. In this way we avoid an unnecessary security risk (more than one paranoid will thank me 🙂).

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.

Clarification: the guide (and the script) are made for debian or derived distros, but broadly speaking it should be useful to anyone, taking into account the particularities of each distribution.

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:

Setting up Sonata

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

Adding MPD to login

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).

MPDroid

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)

Now you can use your Smartphone as a remote control for MPD (no need to have Sonata running). And if what you want is to listen to music from your PC directly from your cell phone, from MPDroid you must enter «Settings» -> «Outputs» -> Select «My HTTP Stream» -> In the options menu of the main interface select "Streaming" (It may take a few seconds to load the music, please be patient 😉).
I hope it has served you, and comment that you found the script, since it is the first one that I make relatively complex. Cheers!

Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Tammuz said

    very useful and well explained

    1.    TheSandman86 said

      Thank you very much, I am glad that it is useful to you. Cheers!

      1.    elynx said

        Did you go to Ubuntu ?.

        Weren't you on Crunchbang Linux?

        1.    TheSandman86 said

          I'm temporarily on Xubuntu (due to steam) since I had a couple of problems with Crunchbang, but I plan to return, since it is the distro in which I feel more comfortable.

  2.   ermimetal said

    When I get home, I'm going to try it, and I know it's very good

  3.   TheSandman86 said

    The incredible thing is the low consumption of resources that it has, that alone is worth giving it a try.

  4.   helena_ryuu said

    Excellent post, mpd is cool.

    1.    TheSandman86 said

      Thank you very much!

  5.   Yoyo Fernandez said

    Ofú !!! :OR

  6.   B1tBlu3 said

    Thank you very much, it was useful to me, now I can change my music sitting from the throne in the bathroom ... hahaha.

    1.    TheSandman86 said

      Hahaha, now I think I have achieved my goal: to simplify someone's life, I feel fulfilled 😉

  7.   car_96 said

    Very good tutorial, before I used the automatic script that they gave in the Arch wiki, but they removed the Link and this tutorial helped me (the script did not, it marked an error).
    The bad thing is that now to install a client on my Nokia E5 I need thousands of things xx

    1.    TheSandman86 said

      What error did the script mark you? I'm glad the tutorial was helpful to you. If you can install the client on the nokia, pass its name in case it works for someone else.

  8.   Leper_Ivan said

    Very good! Congratulations.

    1.    TheSandman86 said

      Thank you!!!

  9.   auroszx said

    Excellent 🙂 MPD is king. I would just like a client like Cantata for KDE, for GTK.

    1.    TheSandman86 said

      Yes, the possibilities that MPD gives you are very varied. What differences does Cantata have compared to other clients? Now I am testing Ncmpcpp (from the terminal) and the truth is that it is very good and complete, it surprised me for good.

  10.   mario said

    Coincidentally I was reading this: http://www.lacocina.nl/artikelen/how-to-setup-a-bit-perfect-digital-audio-streaming-client-with-free-software-with-ltsp-and-mpd

    when I stumble upon your article. Does this combination seem reasonable to you?
    I want to apply it but my system is LMDE KDE created by Schoejle. It is excellent and very intuitive, but like others it does not allow a bitperfect reproduction. Can what you wrote be combined in any way with what that article says? Is it necessary to do so? Thank you for your patience.

  11.   TheSandman86 said

    I think it should be possible, MPD is very versatile, therefore I would think that the most complicated thing would be the LTSP configuration (with which I have no experience) but as for what I put in MPD you should not have problems, The only thing I recommend is not to use the script, and read the commented configuration file to see which options are best suited to what you need.

    1.    Ronald van Engellen. said

      My Spanish is not so good, but I think you mean if bitperfect playback can be combined with a local mpd installation instead of usage with LTSP?

      The answer is yes. Have a look at http://lacocina.nl/audiophile-mpd to see how you can turn any computer running mpd into a bit perfect streamer.

      It also contains information and scripts to automatically create a bit perfect mpd.conf, especially the audio_output {alsa…} section, which is critical for bit perfect playback.

      Regards,
      Ronald

  12.   MLAB. said

    I get an error when trying to use MPDroid: /

    Connection Failed

    Connection to MPD-Server failed! Check if the Server is running and reachable. (Unable to resolve host "http://192.XXX.XXX.XXX": No address associated with hostname.)

    Any idea?

    1.    TheSandman86 said

      How strange, did you check that MPD is working correctly on your PC? And are you connected to the same network with your phone and with your PC?

      1.    MLAB. said

        Everything works fine on my computer, the problem seems to be that it doesn't work in JellyBean 4.2

  13.   TheSandman86 said

    I use it on my phone with jellyBean 4.1.2 and I have no problems, it could be something else. If you can give me a link with a copy of your mpd.conf and some screenshot of the MPDroid settings maybe we can see where the problem is.

  14.   Gabriela said

    Hello good, until recently I discovered mpd and since I have tried everything and I do not know how to solve the problem I have, I have done several things that I have seen in various forums but I have not been able to solve it. The problem is the following

    Failed to bind to '127.0.0.1:6600': Address already in use

    I have changed the port and done other things but nothing has worked, I would appreciate your help 🙂

    The error appears just when typing mpd from the console, thanks 🙂

  15.   Victor said

    If this is the «SIMPLE» version, how will the difficult version be…. 🙂

  16.   matias said

    Does anyone know how to configure to listen to music on two PCs? I mean one one I have all the music and in another I want to access that.

  17.   Javilondo. said

    The script link appears to be broken, it takes me to a default template for this site.

  18.   Giovanni garciliano said

    Link to script no longer works, redirects to site root

    1.    TheSandman86 said

      These days I see if I can redo the script since I can't find it to re-upload it since the original was lost and I see if I can update the guide or make a new one.

  19.   Charly said

    everything works fine except when I browse, pressing 5 hangs and sends me the following comment MPD Stored playlists are disabled