Skip to content
ArtMG edited this page Nov 28, 2019 · 12 revisions

This page looks at audio players using Music Player Daemon (MPD)

Historically a lot of the page was focussed on the Volumio wrapper that makes MPD easy to get started with, but it now covers vanilla MPD first.

see also:

  • Audio-Hub
    • Other generic solutions for playing music
  • Media Centre
    • Full media centre solutions for Pi, rather than simple audio
  • [https://github.com/artmg/lubuild/blob/master/help/use/Music-and-multimedia.md]
    • Includes MPD Clients for Remote Control of your Volumio / MPD device
    • also how to create playlists
  • Snapcast
    • SyNchronous Audio Player install steps

For advanced configuration of other services see also:

  • [https://github.com/artmg/lubuild/blob/master/help/configure/Networked-Services.md]
    • DLNA services like ReadyMedia
    • http web server

Music Player Daemon (MPD)

Introduction

Music Player Daemon (MPD) is a Linux service using a client-server architecture - in other words the server daemon MPD is controlled by Music Player Clients (MPC). That means it simply runs through its playlist, leaving the user interaction to the client. It also runs efficiently because it simply reads from input buffers, like web radio streams or local files, and sends to output buffers, like audio subsystems, with minimal messing around.

Compared with UPnP it is a simpler model with MPC allowing remote control of rendering music by MPD. One major difference is that the playlist is held by the rendering server, instead being sent track by track by the remote control point client. This makes it more of a room-based solution, rather than 'follow-me' controller-based listening.

Links - for more detail see:

  • the MPD wiki [http://www.musicpd.org/]
  • Github source code [https://github.com/MusicPlayerDaemon/MPD]
  • mpd.conf man page [https://linux.die.net/man/5/mpd.conf]
  • ArchLinux article [https://wiki.archlinux.org/index.php/Music_Player_Daemon]

Clients

In some ways the MPD server is the simple bit, and most of the complication comes in the interface.

For remote clients try:

  • Android
    • MPDroid
  • Ubuntu
    • Cantata (or QMpdClient)
  • Mac
    • Cantata (available via Brew)
  • other

A popular option is to use an 'integrated' web-client, in other words the MPD server also a delivers a web interface that you can simply browse to:

  • ympd

Finally, or first for many people actually, is a 'system in a box' approach where you get the full stack of MPD + Web-client + (sometimes) base OS:

  • Volumio
  • Modipy
  • Rune
  • PiBox etc etc

For an exhaustive list of MPC clients see [http://mpd.wikia.com/wiki/Clients].

There is some detail on our client choices at [https://github.com/artmg/lubuild/blob/master/help/use/Music-and-multimedia.md] and that section is

TO BE MOVED IN

and have as a 'More on clients' section further down.

Installation

sudo apt install mpd

Although that is pretty simple, it does need to pull in an awful lot of libraries, and might eat more than half a gig of disk space.

Playlists

The playlist location is specified in /etc/mpd.conf - for example /var/lib/mpd/playlists. However MPD does not appear to enumerate subfolders so all playlists should go directly into this folder. The folder location may, however, be a symbolic link.

Each m3u file contains 1 line per track, optionally preceded by #EXTM3U metadata. The path will not accept quotes, and must be relative to the Music folder specified in the config file.

For information on metadata tagging limitations in MPD see [https://opensource.com/life/16/11/getting-mpdroid-working-archphile-based-box]

Remote playlists

If you want to use m3u playlists outside the above folder, e.g. in specific folders amongst your music, you might need to turn on a plugin for remote playlists. However, at MPD version xxx ALL plugins are ENABLED by default.

sudo editor /etc/mpd.conf

playlist_plugin {
    name "m3u"
    enabled "true"
}

path relativity

playlist is relative path to the music or playlist directory according to [https://www.musicpd.org/doc/api/html/PlaylistAny_8hxx.html]

check the current song's path with mpc -h myhostname current -f %file%

Mopidy has more flexibility about how playlist paths are made relative

  • [https://docs.mopidy.com/en/latest/ext/m3u/]

IN

From [Networked-Services.md]

# mkdir /media/Music
# chmod -R 777 /media/Music
# credit - http://www.raspyfi.com/ho-to-install-mpd-on-an-existing-debian-installation-on-raspberry-pi/

# credit - http://www.instructables.com/id/Linux-music-server-controlled-by-an-Android-device/
sudo apt-get update && sudo apt-get install -y mpd

sudo nano /etc/mpd.conf
# ? bind_to_address "any"

sudo /etc/init.d/mpd restart

# other packages required?

# does this sort perms issues? - http://www.reddit.com/r/raspberry_pi/comments/1w8ia0/raspberry_pi_mpd_server/

# alternative using archlinux (quicker boot if you don't need HDMI)
# http://hempeldesigngroup.com/embedded/stories/raspberry-pi-setup-as-mpd-sever/

# troubleshooting - http://mpd.wikia.com/wiki/Music_Player_Daemon_HOWTO_Troubleshoot
# ArchLinux page on setup - https://wiki.archlinux.org/index.php/Music_Player_Daemon
# ArchLinux page on troubleshooting https://wiki.archlinux.org/index.php/Music_Player_Daemon/Troubleshooting
# or consider whether mopidy might be simpler https://docs.mopidy.com/en/latest/installation/raspberrypi/

Volumio

The rest of this article is mainly focussed on Volumio, although it may contain some items that could be
brought up into the main MPD sections.

Old intro

This was refocussed to MPD solutions in general, which include Volumio but as this has begun to add too many features, it does not always have the advantage of simplicity that MPD itself had. It will now also consider alternatives such as:

  • Archphile
  • Rune Audio

Although Volumio can be used with its own built-in web interface, as well as sharing media sources across your network, it also comes with the MPD (Music Player Daemon) server built-in.

First we cover MPD in Volumio, then MPD in general, and the last sections are about installing MPD on its own.

This page focuses on using your Audio Hub via an MPD client on your phone or computer.

  1. Setting up RPi distro and networking
  2. MPD services
  3. MPD client features

Volumio MPD specifics

File locations

These are specified in /etc/mpd.conf but unless you make changes via the web GUI, they might not persist. For permissions issues see Diagnose section below.

  • /var/lib/mpd - sources of music
    • /var/lib/mpd/music
      • add symlinks to your media files here (rather than copying the music itself, as this might not persist with upgrades or rebuild)
      • to ignore certain files and subfolders: - use a .mpdignore file in the parent - each line contains shell wildcards to ignore - see [https://volumio.org/forum/how-exclude-folders-from-library-update-t3118.html]
    • /var/lib/mpd/playlists
      • from Volumio 2 this feature is DEPRECATED!!
    • /var/lib/mpd/tag_cache is the mpd db_file

for log locations see Diagnose section below

  • symlinks

    • NB: v1.5 and v1.55 bug - new symlinks fail to appear in the Browse tab according to FAQ
      • create in a sub location for now!
  • /data

    • /data/INTERNAL
      • sram (used to be /var/run/shm) ?
      • also mounted as /mnt/INTERNAL
      • also shared with samba as Internal Storage
      • see [https://volumio.org/forum/sram-internal-storage-t4564.html]
    • /data/playlist
      • playlists saved from Web UI
      • See Playlist section below
    • /data/favourites
      • My Web Radios and Radio Favourites (see below)
    • /data/configuration
      • hierarchy of internal configuration details stored in config.json files

Copied from Layout section above

If you want to add songs directly onto the SD card media, expand the partition as per FAQ entry: https://volumio.org/forum/faq-and-the-answers-for-t1545.html

The alternative, to create an extra FAT32 partition on the end, would still leave you having to add an extra mount option for the partition and then create the symlink (see in FAQ https://volumio.org/forum/faq-and-the-answers-for-t1545.html ) and you still risk loosing the partition when re-flashing newer version.

Once you have done this you may copy files into /var/lib/mpd/music - if you are doing this remotely, then use the WEBRADIO share as this one is non symlinked to a mount point, but is just a folder containing .pls files

Volumio Playlists

Includes information on Web Radios.

Since Volumio2, the way playlists and web radios work has changed. Instead of supporting .PLS and .M3U files being copied via samba shares, all the configuration must be done through the Web UI or created manually as below.

Also these playlists and radios do NOT appear in MPD client's library's lists of Playlists or Streams

  • Playlists
    • individual files in /data/playlist
    • sample entry
      • {
      • "service": "mpd",
        
      • "uri": "mnt/NAS/Music/Adele/25/10 All I Ask.ogg",
        
      • "title": "All I Ask",
        
      • "artist": "Adele",
        
      • "album": "25",
        
      • "albumart": "/albumart?web=Adele/25/large&path=%2FNAS%2FMusic%2FAdele%2F25"
        
      • },
  • My Web Radios
    • each is an entry / section in /data/favourites/my-web-radio
    • sample section
      • {
      • "service": "webradio",
      • "uri": "http://yp.shoutcast.com/sbin/tunein-station.m3u?id=1115436",
        
      • "title": "KISS FM",
        
      • "icon": "fa-microphone"
        
      • }
  • Favourite Radios
    • as My Web but the file is /data/favourites/radio-favourites

old

split out the how to from the File Locations section above

# e.g. from ssh session on local 
cd /mnt
find "USB/Media.COPY/Music.COPY/artist folder/album folder" >>"USB/Playlists/my playlist name.m3u"
  • for example scripts to create playlists see
    • [https://github.com/artmg/lubuild/blob/master/help/use/Music-and-multimedia.md]

Web Cover Art

  • sharing Cover Art easily with MPDroid by creating a link in volumio web server
    • see also:
      • [https://opensource.com/life/16/11/getting-mpdroid-working-archphile-based-box]
      • [http://www.katoemba.net/makesnosenseatall/forums/topic/mpodmpad-cover-art-and-volumio/]
      • [https://volumio.github.io/docs/User_Manual/Configure_MPD_Clients_for_albumart.html]
      • [https://volumio.org/forum/album-cover-art-grid-view-file-directory-browsing-mode-t5952.html]

Sharing local files

e.g. to upload music to volumio local SD or USB storage via network

I want to "Upload music to Volumio over the network" which the FAQ says is a breeze, but I cannot browse to the samba shares via PCManFM and they don't appear in Avahi Discovery

  • local samba conf? - [https://github.com/volumio/Volumio-WebUI/blob/master/_OS_SETTINGS/etc/samba/smb.conf]
  • any clues here? - [https://www.reddit.com/r/raspberry_pi/comments/3opic0/volumio_samba_shares/?ref=readnext_3]

See avahi.services file in MuGammaPi

Changing mpd.conf

The file /etc/mpd.conf may be overwritten if you use the web interface after making changes.

See this example [https://volumio.org/forum/huge-mpd-log-file-t2881.html] of how to set log_level "default"permanently by modifying

Diagnose and Troubleshoot

Volumio version

  • In the web GUI see Settings / System / System Version
  • from the console command line use:
# see all version information
cat /etc/os-release 

# extract just the volumio version 
. /etc/*-release
echo $VOLUMIO_VERSION

# date of install
stat /var/log/installer/syslog 
  • WebUI System page says it can look for updates - not sure if it works

Config files

If you want to back up your configuation, here is a list of files to copy

# list of files
/etc/avahi/services/smb.service
/etc/samba/smb.conf
/etc/minidlna.conf
/etc/hostname
/etc/mpd.conf
/etc/fstab

# example command
scp root@kitsnd:/etc/fstab .

Permissions

  • default permissions
    • /var/lib/mpd/music
      • root:root 755
    • /var/lib/mpd/playlists
      • mpd:audio 777 (volumio)
# User `mpd` needs execute permissions on the top directory where all of your music files are. 
# Your music files themselves can be read-only. 
# eg if your music is mounted at /mnt/NAS/music
chmod +x /mnt/NAS/music
# The music files themselves can be 644!
# credit [https://volumio.org/forum/music-nas-not-showing-library-t1497-10.html]

log files

  • /var/log/volumio.log
    • by default there is no separate mpd.log
    • the default log level is fairly verbose
    • see changing mpd.conf above for examples of altering this

see also [https://volumio.org/forum/volumio-log-file-path-t5656.html]

About Volumio

[https://volumio.org/]

Volumio is a dedicated distro, previously known as Raspyfi.

It is based on Linux MPD (Music Player Daemon - see below). It comes with a self-expanding installer ready to go onto an SD card and a simple browser-based interface to configure all options.

Music can be based on an extended partition, another USB or on a NAS.

Installer

This is a dedicated distro, copied onto SD using dd, at which point it is ready to go

Download the installer from [https://volumio.org/], unzip it and dd it on to your micro SD card - see [https://github.com/artmg/MuGammaPi/wiki/Disks#distro-images] for help with this.

Options

If you hold music elsewhere, the minimum SD card size is 4GB (was 2GB), with recommended being 8GB to allow space for auto-update download & rollback [https://volumio.org/forum/what-the-minimum-size-micro-card-for-volumio-t5259.html]

layout

Partition Size Type Explanation
1 64MB FAT boot
2 2.2GB Ext4 Initially contains Squash file (was 1.7, then 2.8)
3 400MB Ext4 Data (since Volumio 2) will expand to fill trailing space on first boot

For more on details of locations see Volumio MPD specifics and File locations below.

old notes

may have been moved below

If you want to add songs directly onto the SD card media, expand the partition as per FAQ entry: https://volumio.org/forum/faq-and-the-answers-for-t1545.html

The alternative, to create an extra FAT32 partition on the end, would still leave you having to add an extra mount option for the partition and then create the symlink (see in FAQ https://volumio.org/forum/faq-and-the-answers-for-t1545.html ) and you still risk loosing the partition when re-flashing newer version.

Once you have done this you may copy files into /var/lib/mpd/music - if you are doing this remotely, then use the WEBRADIO share as this one is non symlinked to a mount point, but is just a folder containing .pls files

Quick Install

  • Write the disk image [https://github.com/artmg/lubuild/blob/master/help/configure/write-Distro-to-flash.md#choice--simpler---dd]
    • REMOVE .img from unzip command line
  • label extra partition
    • sudo e2label /dev/${MEDIA_DEVICE:0:3}3 $MEDIA_LABEL\_data

direct configuration

Volumio is designed to be easy to use, out of the box. With v2.041 it is generally far simpler to use a cabled ethernet connection to http://volumio/ and change your configuration on the simple web GUI.

Hostname, wifi ssid and key, music library location, all these and more are easy to change.

pre-set hostname

for details of how the squash file systems are initially set up see [https://volumio.org/forum/music-card-raspi3-volumio-rc1-t4185.html#p18854]

  • FIRST eject and re-insert the SD card to remount with correct names
echo "Enter new hostname: "
read NEWHOSTNAME

MOUNT_POINT=$MEDIA_LABEL\_data
MEDIA_ROOT=/media/$USER/$MOUNT_POINT

sudo mkdir -p $MEDIA_ROOT/dyn/etc

sudo tee $MEDIA_ROOT/dyn/etc/hosts <<EOF!
127.0.0.1       localhost $NEWHOSTNAME
::1             localhost ip6-localhost ip6-loopback $NEWHOSTNAME ip6-$NEWHOSTNAME
ff02::1         ip6-allnodes
ff02::2         ip6-allrouters
EOF!

sudo tee $MEDIA_ROOT/dyn/etc/hostname <<EOF!
$NEWHOSTNAME
EOF!

# if you also want to set up your wifi then use
# credit [https://github.com/artmg/MuGammaPi/wiki/Rasbian-basics#configure-Wifi-from-command-line] but inserting $MEDIA_ROOT before file path
sudo mkdir -p $MEDIA_ROOT/dyn/etc/wpa_supplicant/
sudo tee $MEDIA_ROOT/dyn/etc/wpa_supplicant/wpa_supplicant.conf <<EOF!
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
    ssid="$WIFI_SSID"
    psk="$WIFI_PSK"
}
EOF!
  • NB: this currently fails to change the Share Server name (etc/samba/smb.conf)
    • do this manually over ssh after completing install
  • what about UPNP / Airplay ???

DAC hardware option

Many DAC drivers are also easy to configure automatically in Volumio.

  • From the Web UI:
    • Volumio / Settings / Playback Options / Audio Output
    • I2S DAC = ON
    • DAC Model = (choose according to your hardware)
      • e.g. IQaudIO DAC Plus
    • Save

Plugins

[https://volumio.github.io/docs/Plugin_System/Plugin_System_Overview.html] [https://github.com/volumio/volumio-plugins/tree/master/plugins]

Multi-room setup

Configure DAC hardware

If using plain Raspbian you will need to configure the DAC manually according to the manufacturer's instructions. To avoid contention configure and test this before installing snapcast.

IQaudIO Pi-DAC+ Full HD Audio Card

see [https://github.com/artmg/MuGammaPi/wiki/Audio-Hub#dac-drivers]

Snapcast

For an introduction to Snapcast, and full installation procedures, see [https://github.com/artmg/MuGammaPi/wiki/multi-room-audio]

Other

icecast

Early multiroom solutions used the icecast radio service locally, with clients tuned to this source. [https://volumio.org/forum/multi-room-audio-system-with-raspberry-icecast-and-volumio-t2569.html]

Client-driven

see Sound@Home for other clients see [https://volumio.org/volumio-android-apps/]

Advanced Configuration

Note that some attempts to tweak configuration files might end up putting the software in an inconsistent state. If you do this you might need to restart from a clean disk image to workaround the issues you caused.

If the option can be changed from the GUI, you are safest to change it there. If there is no GUI option or plugin, then this is how you can set up additional services.

console access

# By default, ssh as user=root and password=volumio
ssh root@volumio

direct changes to SD card

If you wish to access your configuration but can't connect over the network, for instance because you had fixed IP addresses or not yet configured wifi, you can whip out the SD card and modify the files there.

Volumio2 holds its linux root filesystem contents in a Squash Filesystem, which is on the second volumio partition, in volumio_current.sqsh

T.B.C. according to [https://volumio.org/forum/music-card-raspi3-volumio-rc1-t4185.html] the contents of volumio_data/dyn are overlayed during boot, so might it be simpler to edit those? e.g. /media/$USER/volumio_data/dyn/etc


# First back up the old filesystem
cd /media/$USER/volumio
mv volumio_current.sqsh volumio_current.backup.sqsh

# unsquash the files
mkdir -P /tmp/unsquashed
cd /tmp/unsquashed
unsquashfs /media/$USER/volumio/volumio_current.backup.sqsh

# NOW change your files in the /tmp/unsquashed folder

# resquash the modified files
mksquashfs /tmp/unsquashed/squashfs-root/ /media/$USER/volumio/volumio_current.sqsh

Network

To change force network details via config files use:

  • /etc/resolv.conf
    • nameserver IP address
  • /etc/hostname
    • computer name
  • /etc/network/interfaces
    • fixed IP and gateway
    • wireless network settings (SSID/PSK)
      • change iface wlan0 inet manual to dhcp
      • add (indented) wpa-ssid MySsidName and wpa-psk MySecret
      • credit - [https://volumio.org/forum/configure-volumio-wifi-without-using-cabled-ethernet-t3953.html]

Note that your changes here will NOT be reflected if you go into Volumio's configuration interface.

generic services

DLNA test on Volumio

See also:

  • advanced configuration of ReadyMedia
    • [https://github.com/artmg/lubuild/blob/master/help/configure/Networked-Services.md]

By default MiniDLNA (now known as ReadyMedia) is installed but not configured

Is this config change the same as using web interface to click DLNA Library Server = ON

# https://volumio.org/forum/how-start-the-dlna-server-for-volumio-the-t2401.html
# uncomment out the line  media_dir=
vi /etc/minidlna.conf

service minidlna restart

### STILL TO DO 
# friendly name in minidlna.conf?
# or in /etc/upmpdcli.conf according to # credit - https://volumio.org/forum/faq-and-the-answers-for-t1545.html
# 

announce the shares

Any local music files are shared automatically as part of the default configuration. To improve your ability to see these shares on the network you could ensure that Avahi announces them.

# Manually add a generic Samba entry into the local list of services to advertise 
cat > /etc/avahi/services/smb.service <<EOF!
<?xml version="1.0" standalone='no'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
 <name replace-wildcards="yes">%h</name>
 <service>
   <type>_smb._tcp</type>
   <port>445</port>
 </service>
</service-group>
EOF!

# restart the Avahi service
service avahi-daemon restart

snapcast-volumio-ui

If you use Volumio, this gives you a handy web interface to set the relative volume of multiple snap clients

Project URL: [https://github.com/atoomic/snapcast-volume-ui]

Stack: Dancer2 application, written in perl, deployed onto plack web engine.

These instructions were tested on a headless Raspberry Pi 2 model B, using Raspbian Jesse Lite (2017-02-16), which is a reasonably minimal base image, so they should hopefully include all the dependencies you need.

Advanced configurations could involve:

  • web server that is more streamlined or scalable than plack,
  • a perl-and-cpan driven build, such as perlbrew and cpanm, though it might take for longer to install fresh

However here we focus on getting the software functioning in the minimum time with a minimum of effort

You could use one of your snapcast client devices, as it might be reasonably idle, but these instructions do not depend on any local snapcast installation or configuration.

### INSTALL FROM REPOS

# install dependency packages - translated from requires list in 
# [https://github.com/atoomic/snapcast-volume-ui/blob/master/cpanfile]
# time hires is in perl core included in raspbian lite
sudo apt install -y libdancer2-perl libplack-perl libclass-accessor-class-perl libtest-harness-perl libnet-telnet-perl libtemplate-perl libjson-xs-perl libfile-fcntllock-perl

# now let's copy the code from the git repo
# v.11 not ready yet
# SNAPVOL_VERSION=0.11 
SNAPVOL_VERSION=0.12.0
SNAPVOL_BRANCH=snapcast/v$SNAPVOL_VERSION
# create the destination folder
mkdir -p ~/snapvol-$SNAPVOL_VERSION/
# download the branch, following redirects and showing errors
curl -SL https://github.com/atoomic/snapcast-volume-ui/tarball/$SNAPVOL_BRANCH  | tar -xzC ~/snapvol-$SNAPVOL_VERSION/ --strip-components=1

# Workaround because I couldn't find a Simple Accessor package in the repos
sudo mkdir -p /usr/share/perl5/Simple
cd /usr/share/perl5/Simple
sudo curl -O https://raw.githubusercontent.com/atoomic/Simple-Accessor/master/lib/Simple/Accessor.pm
cd ~/snapvol-$SNAPVOL_VERSION/


### Check your network details

# get the IP for my server and mac addresses for my clients
# please change these to your own hostnames
ping -c 1 mysnapserver
ping -c 1 mysnapclient1
ping -c 1 mysnapclient2
arp

### Configure

cd ~/snapvol-$SNAPVOL_VERSION/
cp config.yml.example config.yml
# set your own snapcast server IP & colors (view Configuration section)
# server host must be IP address
editor config.yml

### TEST

plackup -E development -p 8080 ./bin/app.psgi

# now browse to http://thishostname:8080/ to make sure it works, 
# observing the console output in case of issues


### INSTALL AS A SERVICE

cd systemctl
cp snapcast-ui.service.example snapcast-ui.service
editor snapcast-ui.service

You must change the Execstart line to be (manually replacing $SNAPVOL_VERSION with the version number)


ExecStart=/usr/bin/plackup -E production -p 8080  /home/pi/snapvol-${SNAPVOL_VERSION}/bin/app.psgi

now carry on with

editor Makefile

Unfortunately the current version of the Makefile does not account for the debian systemd path convention /lib/systemd/system/ and so you will have to remove the /usr from the beginning of it to leave but don't forget that makefiles are fussy - must have single TAB not spaces!

    install snapcast-ui.service /lib/systemd/system/

And finish with

sudo make all

# it should show as active, but is not yet 'enabled' for autostart so
sudo systemctl enable snapcast-ui.service

reboot and test again.

to recreate the file

cat << EOF! > snapcast-ui.conf
# edit this file for personal setup
SNAPCASTUI_PERL=/usr/share/perl5
SNAPCASTUI_HOME=$(dirname "$(pwd)")
EOF!
Clone this wiki locally