Raspberry Pi MPD

I’ve just setup MPD (Music Player Daemon) on my Rpi and it works beautifully.

Let get down to it:

Taking advantage of debian APT it is very simple to set it up:

sudo apt-get install mpd mpc
Some may need to install alsa-utils (amixer, etc...)
sudo apt-get install alsa-utils

Where mpd is the daemon and mpc is the client.

Configuration is all done on the file located in /etc/mpd.conf

I saw in a blog, somewhere I don’t remember how to setup the audio output:

audio_output {
        type            "alsa"
        name            "My ALSA Device"
        device          "hw:0,0"        # optional
#       format          "44100:16:2"    # optional
#       mixer_device    "default"       # optional
#       mixer_control   "PCM"           # optional
#       mixer_index     "0"             # optional
}

After this I’ve signed up at last.fm

and added this into the configuration file:

input {
       plugin          "lastfm"
       user            "vcasinha"
       password        "thatspersonal"
}

To make this all work we may need to setup the system to load audio driver:

# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
# Parameters can be specified after the module name.
snd_bcm2835

Then you can decide which output to use with the following command:

sudo amixer cset numid=3 1

Where 1(one) means Stereo Jack output and 0(zero) HDMI audio output.

On my setup I’m using XBMC audio output through HDMI and MPD output through Stereo Jack.

Once the setup is done the MPD service must be restarted with a command like:

sudo /etc/init.d/mpd stop
sudo /etc/init.d/mpd start
#or
 sudo /etc/init.d/mpd restart

You can control it manually with ease:

#check mpd status
mpc
volume:100%   repeat: on    random: off   single: off   consume: off
#it seams ready let's add a internet radio 
mpc add http://s1.radio.lclhst.net:1337/
mpc play
Minimal, Techno, Electro Sets @ http://radio.lclhst.net/: Patrick Schulz - Promotional Mix - October 2008
[playing] #1/1 0:04/0:00 (0%)
volume:100% repeat: on random: off single: off consume: off

Or you can install an iOS App like mpod or Android MPDroid to manage everything.

Good luck and good music

miro

29 Comments

  • Reply Naundorf |

    With help of your tutorial I have installed MPD on my Pi and it works, many thanks.
    Only one exception: lastfm doesn’t function, although I have an account there.
    In mpd.log I get the following error messages:

    config: option ‘user’ on line 188 was not recognized
    config: option ‘password’ on line 189 was not recognized

    Do you have an idea how to solve this problem?

    Regards
    Ludus

    • Reply Vladimiro Casinha |

      Hi,
      which version of MPD do you have installed?

      If it is 0.15 the configuration file should be something like this:
      input {
      plugin "lastfm"
      user "my_username"
      password "my_password"
      }

      If it’s 0.16:
      playlist_plugin {
      name "lastfm"
      user "my_username"
      password "my_password"
      }

      Hope it helps.

  • Reply Ludus |

    Hi,
    I’m using version 0.16.7

    I have changed the config file and now it seems to work.

    But there is still an error message in the log file:

    avahi: Failed to create client: Daemon not running

    Is this important for anything?

    Thanks for your help
    Ludus

    • Reply Vladimiro Casinha |

      Great!
      That means avahi daemon is not running.
      Try to start it and see if you have the same issue.
      I am not sure, but I think it depends on D-BUS.
      Check if it is running too.
      I think this problem is not related to mpd. :)

      miro

  • Reply Ludus |

    A question in addition:
    How do I contact lastfm, how do I select some song?
    (I’m using the Mpod app’)

    • Reply Vladimiro Casinha |

      On Mpod you can control MPD lastfm plugin going to more (lower left corner) and the selecting lastfm.
      Then you may pick music by genre, year, artist, tag, etc…

      Cheers
      miro

  • Reply Ludus |

    You are right, running avahi daemon has no influence on mpd function. So the error message seems to be needless.

    On Mpod I have found the button to play lastfm and all works fine.

    Again many thanks for your help

    Ludus

  • Reply Jeanrocco |

    Hello, for nice stereo sound I plugged a http://www.amazon.com/Syba-SD-CM-UAUD-Adapter-C-Media-Chipset/dp/B001MSS6CS in one of the USB port. If you have other devices in the USBs, type ” aplay -l ” to get which audio card your device is, (mine is card 1) then set it in /etc/mpd.conf in the ALSA output.

    # For network
    #bind_to_address “localhost”
    bind_to_address “any”

    # An example of an ALSA output:
    #
    audio_output {
    type “alsa”
    name “My ALSA Device”
    # device “hw:0,0″ # optional
    device “hw:1,0″ # port USB Audio
    format “44100:16:2″ # optional
    # mixer_device “default” # optional
    # mixer_control “PCM” # optional
    # mixer_index “0″ # optional
    }


    mixer_type “software” #you get volume control MPDroid

    That’s it ! enjoy

  • Reply Max |

    Hi,
    great tutorial. All worked fine but….
    After installing MPD on my Raspi I’ve tried to add minidlna.
    The setup restarted mpd (that was working fine) and after that I cannot restart anymore.
    The error is mpdSegmentation fault and it seems it can’t find libid3tag.so.0 anymore.

    i’m struggling around to restore this lib but Im not able (yes, im a n00b).

    Can U pls tell me how can I fix it ?

    Thanks a lot.
    Max

  • Reply ben |

    when i start it up get an error saying could not create pid file “/var/run/mpd/pid”: permission denied. cant work out how to give it permission to write in that location

      • Reply ben |

        Wow thanks for the quick reply. Unfortunately it still comes up with that error after trying both methods. it also says “Failed to create socket: Address family not supported by protocol” dont know if that helps. Here is every thing it says when i try to run it:

        [....] Starting Music Player Daemon: mpdlisten: bind to ‘[::1]:6600′ failed: Failed to create socket: Address family not supported by protocol (continuing anyway, because binding to ’127.0.0.1:6600′ succeeded)
        daemon: could not create pid file “/var/run/mpd/pid”: Permission denied
        failed!
        Thanks for the help
        Ben

  • Reply Davy Landman |

    exactly what I wanted to do, mpd on the analog plug, xbmc on the HDMI.

    using your tutorial I got it working (on raspbmc), but when I started a movie on xbmc, it hang and stopped the music output from mpd.

    I couldn’t find any real error messages, but had to reboot to get into a sane state..

    what did you do to make sure xbmc doesn’t interact with mpd on analog?

  • Reply olls |

    Thanks :D
    After playing around, I got this working nicely.
    The only think I can’t work out is how to get music playing from last.fm, do you have a solution?

  • Reply omega1 |

    Hello!

    I need software that can play a live audio stream (AAC+ not MP3), I note from what I saw in the tutorial that MPD should work for what I want:

    #check mpd status
    mpc
    volume:100% repeat: on random: off single: off consume: off
    #it seams ready let’s add a internet radio
    mpc add http://s1.radio.lclhst.net:1337/
    mpc play
    Minimal, Techno, Electro Sets @ http://radio.lclhst.net/: Patrick Schulz – Promotional Mix – October 2008
    [playing] #1/1 0:04/0:00 (0%)
    volume:100% repeat: on random: off single: off consume: off

    If I just change the above stream to mine.

    My questions are as follows:

    - Where can I put this code so that it autostarts? Should I copy it into /etc/profile ?
    - Will MPD play AAC+ audio streams?
    - If I leave the ‘repeat: on’ will it continuously play my live stream and hopefully recover should there be a network issue or similar? My intention is that is always plays from start.

    Thank you in advance for your comments and suggestions.

  • Reply mi |

    There is a distribution ready for what you are describing… Plus it has lot of tweaks and optimizations… It works with lot of usb dacs out of the box… Give it a try…
    http://www.raspyfi.com

  • Reply Dude |

    Hey there!

    Many thanks for this tutorial.
    Unfortunately I have no idea how to access last.fm via the MPDroid app for android. Thought I’ll find some new option or something. But can’t find anything :-/

    Any hints?

    Thanks advance!

    Dude

Post a comment