I posted a video of my Raspberry pi music player with VU meter here:
https://www.reddit.com/raspberry_pi/comments/j8y9f0/i_built_a_raspberry_pi_music_serve A lot of people in that thread asked me for a "step by step" on what I did. So I put together a document on what I did. I'd like to get as much feedback and as possible on whether the document makes sense, and things you think I should change. This is a pretty simple project. I hope this documentation makes sense.
As a side note, I reconfigured the way the 3 components were stacked and recorded this video:
https://www.youtube.com/watch?v=zwvypfZkF_0 I then posted a guide ojn how to build the Pi music player here:
https://www.reddit.com/raspberry_pi/comments/jbt34g/the_raspberry_pi_music_player_build/ Well, that guide had a bunch of errors and a convoluted script, so I cleaned it up, made the script longer, but easier to use and cleaned up some of the language in the guide. So, I present to you, version 2 of my guide. A comments and constructive criticism welcome.
Raspberry Pi Music Server Setup
Assumptions
Hardware setup
Items needed
- A Raspberry Pi (Duh!)
- A USB DAC
- A USB cable for your DAC
- 2 sets of RCA cables
- A power adapter for your Pi
- A power adapter for your DAC (It should have come with one)
- A VU meter with RCA in and out
Items I Specifically Used
Hardware Connection
- Connect Raspbery Pi to to DAC using USB Cable.
- Connect the DAC to the VU meter using RCA cables
- Connect VU meter to your amp/receivepowered speakers using RCA cables.
- Connect all 3 devices together using Command™ strips
Software Setup
Install MPD backend
- ssh into your Raspberry Pi
- type sudo apt install -y mpd mpc ncmpcpp to install mpd
- type sudo addgroup mpd audio to give mpd the right to your audio device
- reboot your Raspberry Pi: sudo reboot
Configure DAC and mpd
Finding you DAC
You need to find the hardware value for your DAC. The easiest way to do that is to run the command aplay -l
For my Pi, I get the following output:
[email protected]:~ $ aplay -l **** List of PLAYBACK Hardware Devices **** card 0: Headphones [bcm2835 Headphones], device 0: bcm2835 Headphones [bcm2835 Headphones] Subdevices: 8/8 Subdevice #0: subdevice #0 Subdevice #1: subdevice #1 Subdevice #2: subdevice #2 Subdevice #3: subdevice #3 Subdevice #4: subdevice #4 Subdevice #5: subdevice #5 Subdevice #6: subdevice #6 Subdevice #7: subdevice #7 card 1: OOUSB [JDS Labs OOUSB], device 0: USB Audio [USB Audio] Subdevices: 1/1 Subdevice #0: subdevice #0 card 1: OOUSB [JDS Labs OOUSB], device 1: USB Audio [USB Audio #1] Subdevices: 1/1 Subdevice #0: subdevice #0 [email protected]:~ $
On this list,
JDS Labs OOUSB is my DAC.
The two pieces of information I will need from this is the name are:
- The DAC name: JDS Labs OOUSB
- The card number (1) and the subdevice number (0)
Music location
The next thing you need to know is where you are storing your music:
- Locally on the SD Card or an external hard drive
- On a network share
- On another mpd server
Local Music
The setup of local music goes beyong the scope of this document. You will need to know how to copy music onto your pi.
Network Music
If you have your music on a NAS or some other server, mpd can read your music from either an SMB/CIFS (Windows File Sharing) or NFS share.
Another mpd server
If you another mpd server, you can setup an mpd proxy server. The proxy server needs to be pointed to the music library, but the main server shares it's database with the proxy server. This has two advantages:
- When you connect your proxy server to the main mpd server, the music library becomes INSTANTLY available. No need to scan the library
- When do you scan the library your proxy server kicks the request over to the main server to do the scan. Since the main server usually will have the files local to it, the scans go much faster.
Configuring mpd
- Now you will need to configure mpd. To do that, type sudo nano /etc/mpd.conf
- The first line you want to look for is #music_directory "/valib/mpd/music"
- Remove the # in the front of the line, if there is one. Then edit /valib/music/mpd to point to your music.
- This link will take you to the mpd documentation for setting your music directory.
- Next look for this block of text:
audio_output { type "alsa" name "my ALSA device" device "hw:0,0" # optional # mixer_type "hardware" # optional # mixer_device "default" # optional # mixer_control "PCM" # optional # mixer_index "0" # optional }
Change the following lines:
- name, add the name of your DAC you got earlier from aplay
- device should set to your card number and subdevice number. In my case it would be set to hw:1:0
- Uncomment mixer_type by removing the # and change it to hardware.
Other lines to change:
- I recommend turning on ReplayGain, by editing the following line: #replaygain "album". Remove the # and change it from album to auto
- Fine the line bind_to_address "localhost" and change localhost to any
Restart mpd: sudo systemctl restart mpd
You will now need to scan your music. Run the command mpc update. mpc will not give you any indication it's scanning music. You just kind of have to wait.
At this point the server configuration is done. You will now want to test your music to see if something will come out of your speakers. The only way to do that is to use a
front-end to control mpd. Luckily we installed command line front-end. Type ncmpcpp When the app loads, type 4 to see your music library. Use the arrow keys to find a song and hit Enter. After a few seconds, a song should start playing. To stop the music press p. If music plays, your backend is now setup.
Configure A Front-End
In order to play anything on mpd, you need to use a front-end to control it. Earlier you installed 2 command-line front ends.
You can stop right here and install a front end on your phone. I use Rigelian on my iPhone. There are also Android clients.
But I wanted to install a web-based front-end on my Pi. The best one I found was called
RompR RompR Installation
Rompr installation is a bit involved:
- Install a web server on the Pi
- Copy RompR on to the server
- Configure your web server to use RompR
Configuring RompR is a pretty geeky. But, fear not! I worte a script which SHOULD do it all for you. All I can say is that it Works For Me™ the two times I did it.
So rather than detail the lengthy process of setting up RompR and nginx, I'm just going to give you my script to try.
Place the script on the root of the pi user's home drive (/home/pi/).
Ok, here are the contents of the file:
install.sh #!/bin/bash # Rompr install script This script is alpha quality at best. It will work with Raspbian from 10/10/2020 that' fully patched. # I tried to script all the steps needed to from the RompR web page. # This script is INSECURE. It uses a lot of sudo commands and assumes you'll run it as the pi user. #Install nginx web server, php and other needed coponents sudo apt install -y nginx php-curl php-sqlite3 php-gd php-json php-xml php-mbstring php-fpm imagemagick # Add connection timeout to the end of your mpd configuration file echo -e '\nconnection_timeout "120"\n' | sudo tee -a /etc/mpd.conf sudo systemctl restart mpd # Switch to the web root directory cd /vawww # Copy RompR down using git sudo apt install -y git sudo git clone https://github.com/fatg3erman/RompR.git # Create needed prefs and albumart directories sudo mkdir /vawww/Rompalbumart sudo mkdir /vawww/Rompprefs # change permissions on the RompR directory, so the Nginx web server has access to it. sudo chown -R www-data /vawww/RompR sudo chgrp -R www-data /vawww/RompR # Read the hostname into a variable host=$(hostname) # Update default nginx config as per RompR documentation sudo sed -i 's/ default_server;/;/' /etc/nginx/sites-available/default #Create RompR config file echo -e "server {\n\n listen 80 default_server;\n listen [::]:80 default_server;\n\n root /vawww;\n index index.php index.html index.htm;\n\n server_name hostname.of.your.computer;\n\n client_max_body_size 256M;\n\n # This section can be copied into an existing default setup\n location /Romp {\n allow all;\n index index.php;\n location ~ \.php {\n try_files \$uri index.php =404;\n fastcgi_pass unix:/varun/php/php7.3-fpm.sock;\n fastcgi_index index.php;\n fastcgi_param SCRIPT_FILENAME \$request_filename;\n include /etc/nginx/fastcgi_params;\n fastcgi_read_timeout 1800;\n }\n error_page 404 = /404.php;\n try_files \$uri \$uri/ =404;\n location ~ /albumart/* {\n expires -1s;\n }\n }\n}\n" > /home/pi/rompr # Add your Raspberry Pi's hostname into the rompr config file sudo sed -i "s/hostname.of.your.compute$host/" ~/rompr # Copy the RompR config file into the nginx config directory and change it's permissions to match the other files in that directory sudo cp ~/rompr /etc/nginx/sites-available sudo chmod 644 /etc/nginx/sites-available/rompr # Enable the RompR config sudo ln -s /etc/nginx/sites-available/rompr /etc/nginx/sites-enabled/rompr # Update php.ini with required settings echo -e "allow_url_fopen = On\nmemory_limit = 128M\nmax_execution_time = 1800\npost_max_size = 256M\nupload_max_filesize = 10M\nmax_file_uploads = 200\n" | sudo tee -a /etc/php/7.3/fpm/php.ini \# Enable php-fpm daemon and nginx sudo systemctl enable php7.3-fpm sudo systemctl enable nginx # Restart php and nginx sudo systemctl restart php7.3-fpm sudo systemctl restart nginx echo "Install is complete. You should be able to access your music server by pointing a browser at http://$host/RompR"
type chmod +x ./install.sh to make the script executable
Run the script by typing ./install.sh
Hopefully it won't throw any errors. If it does, then you will need to manually edit a bunch of config files to clean it all up. The next version of the script will do proper backups of the files.
Rompr Configuration
Once the script is done running, you can access RompR by going to the URL provided at the end of the script. Once you close the Paypal donate screen, you should see the following screen:
https://preview.redd.it/fvr9f2sntwt51.jpg?width=1455&format=pjpg&auto=webp&s=fbb70304838c81cb18db7cadc4991e66fcccfa8a On the left-hand side, click on Update Music Collection Now and wait for RompR to update with your music.
When the music has finished updating, you will see a list of all your artists down the left-hand side.
There are plenty of other things to configure in RompR.
submitted by