Raspberry Pi

How to Turn Raspberry Pi into Home Music Server

In our free time, most of us like to listen to music, for this, they search for the music files and play them. For such users who like to listen to music, this is the perfect guide, as it will help you to learn the method to turn your Raspberry Pi into a home music server. But wait! For those readers who do not know about the music server, the music server is a platform where you can add your favourite music collection and access them quickly for enjoying listening to them using a simple user-friendly interface.

There are a lot of music servers like Kodi and Emby which can be installed on the Raspberry Pi to turn it into a home music server, but the most convenient music server is mobidy whose installation and setup have been discussed in this write-up.

How to install the Mopidy on the Raspberry Pi

First, let us make sure all the packages of the Raspberry Pi operating system are up to date by using the command:

$ sudo apt update && sudo apt full-upgrade -y

Once all the packages are up to date, we will install the Mopidy by downloading its apt-key using the command:

$ wget -q -O - https://apt.mopidy.com/mopidy.gpg | sudo apt-key add -

The “OK” in the output is confirming the apt-key of Mopidy has been successfully added, now we will add the installation files of Mopidy in the Raspberry Pi repository using the command:

$ sudo wget -q -O /etc/apt/sources.list.d/mopidy.list https://apt.mopidy.com/buster.list

After this, update the repository of the Raspberry Pi using the command:

$ sudo apt update

For the installation of the Mopidy on Raspberry Pi using the command:

$ sudo apt install mopidy -y

For the confirmation of installation of the Mopidy, check the version of the installed Mopidy package using the command:

$ mopidy --version

Now we will add this Mopidy user in the video group of the Raspberry Pi using the command:

$ sudo adduser mopidy video

To run the service of the Mopidy so that it can run in the background upon Raspberry Pi reboots, use the command:

$ sudo systemctl enable mopidy

How to configure the Mopidy on Raspberry Pi

If you want to access the Mopidy using the web browser or another device, you have to make some changes in the configuration file of Mopidy which is located at “/etc/mopidy/mopidy.conf” by opening it in nano editor (you can use any other editor too):

$ sudo nano /etc/mopidy/mopidy.conf

A file will be open like this:

Now to access it from the web browser add the following lines in the file:

[http]
enabled = true
hostname = 0.0.0.0
port = 6680
static_dir =
zeroconf = Mopidy HTTP server on $hostname

Similarly, if you want to use the 3.5 AV jack for listening to the music instead of the HDMI cable, then add these lines too:

output = alsasink device=hw:1,0

In the above lines of “device=hw:1,0”, “1” is used for the card number and “0” is used for the device, which is mostly used by the AV jack. Save the changes made in the configuration file of Mopidy by pressing CTRL+S and exit the nano editor by using a shortcut key, CTRL+X, now start the Mopidy service using the command:

$ sudo systemctl start mopidy

How to access the Mopidy from a web browser on the Raspberry Pi

To access the Mopidy from the web browser we have to web client of “Iris” using the pip repository by running the command:

$ sudo python3 -m pip install Mopidy-Iris

Now we have to provide the access sudo permission to the IRIS by using the command:

$ sudo sh -c 'echo "mopidy ALL=NOPASSWD: /usr/local/lib/python3.7/dist-packages/mopidy_iris/system.sh" >>/etc/sudoers'

Restart the Mopidy service by using the systemctl command:

$ sudo systemctl restart mopidy

Now open the chromium-browser on the Raspberry Pi and type the following URL address to access the Mopidy from the web browser with the help of an IRIS web client:

http://raspberrypi:6680/iris/

How to add music to the Mopidy

To add the music from the directory of the Raspberry Pi to the Mopidy, we need a Mopidy-Local extension that can be installed using the command:

$ sudo python3 -m pip install Mopidy-Local

Now we will once again open the Mopidy configuration file using the command:

$ sudo nano /etc/mopidy/mopidy.conf

And add the following line so that we can scan the audio files from the /home/pi/Music folder and add them to the Mopidy:

[local]
media_dir = /home/pi/Music

Save the changes then exit the editor and restart the Mopidy service using the systemctl command:

$ sudo systemctl restart mopidy

To access the files the convenient way is from the web browser open the http://raspberrypi:6680/iris/settings, go the settings of the web page, scroll down the web page and click on the “Start local scan” button:

Then open the URL http://raspberrypi:6680/iris/library/tracks to view the added tracks on the Mopidy:

Conclusion

The Mopidy is a music server that can be installed on the small size computer boards known as the Raspberry Pi. These are very convenient for the users to add the songs in their own customised music playlist and can listen to them by single click from the web browser. In this write-up, we have learned the method of using the Mopidy to turn the Raspberry Pi into a Home Music Server by installing and setting it up on Raspberry Pi.

About the author

Hammad Zahid

I'm an Engineering graduate and my passion for IT has brought me to Linux. Now here I'm learning and sharing my knowledge with the world.