install mopidy - fcorthay/RPi-multiroom-audio GitHub Wiki

This documentation bases on the Mopidy documentation. It consists of a small excerpt targeted to a Raspberry Pi (RPi) with an audio amplifier hat.

Table of Contents

Audio system

Look for the available sound cards:

aplay -l
aplay -l | grep ^card

Play some sound:

source ~/Documents/RPi-multiroom-audio/configuration.bash
echo "amplifier soundcard is \"$AMPLIFIER_SOUNDCARD\""
aplay -D plughw:$AMPLIFIER_SOUNDCARD /usr/share/sounds/alsa/Front_Center.wav
speaker-test -t wav -c 2 -l 2 -D hw:$AMPLIFIER_SOUNDCARD

Change the volume:

alsamixer -D hw:$AMPLIFIER_SOUNDCARD
amixer -D hw:$AMPLIFIER_SOUNDCARD scontrols
amixer -D hw:$AMPLIFIER_SOUNDCARD get Digital
amixer -D hw:$AMPLIFIER_SOUNDCARD sset Digital 60%
amixer -D hw:$AMPLIFIER_SOUNDCARD -q sset Digital 10+

Music server

Install the Mopidy music server:

sudo apt install -y mopidy
sudo usermod -a -G users,video mopidy
sudo chgrp -R users /etc/mopidy
sudo chmod 775 /etc/mopidy
sudo chmod 664 /etc/mopidy/*

Update the configuration:

cat << EOF >> /etc/mopidy/mopidy.conf
[audio]
output = alsasink device=dmix:$AMPLIFIER_SOUNDCARD

[http]
hostname = 0.0.0.0

[local]
media_dir = /home/$(whoami)/Music
included_file_extensions = .flac
EOF

Within this configuration, the dmix prefix permits audio channel mixing. This allows to play to the same device from another application:

sudo apt install -y ffmpeg
alias play2amp="SDL_AUDIODRIVER='alsa' AUDIODEV='dmix:$AMPLIFIER_SOUNDCARD' ffplay -autoexit -loglevel quiet"
play2amp /usr/share/sounds/alsa/Front_Center.wav
Here, the aplay command, instead of play2amp, doesn't work because /usr/share/sounds/alsa/Front_Center.wav is mono, as shown by:
file /usr/share/sounds/alsa/Front_Center.wav

Start the service:

sudo systemctl enable mopidy
sudo service mopidy start

Check what is going on:

sudo service mopidy status | cat
ps aux | grep -i mopidy  | grep -v grep
sudo mopidyctl config

Further information is provided in the docs.

User interface

Install Iris user interface:

sudo apt install -y mopidy-local
#sudo apt install -y mopidy-mpris # is not Mopidy-Iris

Install Iris user interface with pip:

# sudo pip3 install --break-system-packages Mopidy-Local
sudo pip3 install --break-system-packages Mopidy-Iris

Allow mopidy to run the interface:

IRIS_DIRECTORY=`find /usr/local/lib -iname mopidy_iris`
ll $IRIS_DIRECTORY 

sudo sh -c "echo \"mopidy ALL=NOPASSWD: $IRIS_DIRECTORY/system.sh\" >> /etc/sudoers"
sudo service mopidy restart

Start a web browser and go to http://audioAmp.local:6680/iris/ (adapt the hostname).

Music file library

Add music files in ~/Music.

Provide access to the music library:

chgrp users ~/
chmod 750 ~/
chgrp -R users ~/Music

If you have your music anywhere else in the system, update media_dir in /etc/mopidy/mopidy.conf and restart mopidy. If moving the library, start with

sudo mopidyctl local clear
sudo mopidyctl local scan --force

Scan the music library:

sudo mopidyctl local scan

Check the output in order to verify that the media directory was accessed properly and that the files were found.

From the http://audioAmp.local:6680/iris/ browser, refresh the music list ans start playing some.

Playing state

In order to to automatically resume after a reboot, install the Autoplay extension:

sudo python3 -m pip install --break-system-packages Mopidy-Autoplay

Remote control

Mopidy can be controlled per JavaScript Object Notation - Remote Procedure Call (JSON-RPC). Making a JSON-RPC request can be done using curl in a terminal.

The mopidy Application Programming Interface (API) is documented in the online documentation.

Here some examples sent from a terminal:

curl -w "\n" -d '{"jsonrpc": "2.0", "id": 1, "method": "core.playback.get_state"}' -H 'Content-Type: application/json' http://localhost:6680/mopidy/rpc
MOPIDY_SERVER='localhost'
ACTION='core.playback.get_state'
curl -w "\n" -d "{\"jsonrpc\": \"2.0\", \"id\": 1, \"method\": \"$ACTION\"}" -H 'Content-Type: application/json' http://$MOPIDY_SERVER:6680/mopidy/rpc
ACTION='core.playback.pause'
curl -w "\n" -d "{\"jsonrpc\": \"2.0\", \"id\": 1, \"method\": \"$ACTION\"}" -H 'Content-Type: application/json' http://$MOPIDY_SERVER:6680/mopidy/rpc
ACTION='core.playback.play'
curl -w "\n" -d "{\"jsonrpc\": \"2.0\", \"id\": 1, \"method\": \"$ACTION\"}" -H 'Content-Type: application/json' http://$MOPIDY_SERVER:6680/mopidy/rpc
curl -w "\n" -d '{"jsonrpc": "2.0", "id": 1, "method": "core.tracklist.set_repeat", "params": [true]}' -H 'Content-Type: application/json' http://localhost:6680/mopidy/rpc

A simple script allows to make the basic play/stop/pause/resume/next/previous commands (adapt the path):

source ~/Documents/RPi-multiroom-audio/configuration.bash
$AUDIO_BASE_DIR/Mopidy/control.bash pause
$AUDIO_BASE_DIR/Mopidy/control.bash play

Installation

The present installation is presented hereafter:

Mopidy reads music from the disk and sends it to the soundcard.

Check the soundcard hardware parameters:

cat /proc/asound/$AMPLIFIER_SOUNDCARD/pcm0p/sub0/hw_params

Continue the installation process.

⚠️ **GitHub.com Fallback** ⚠️