Gordon999 / Pi-MP3_Player

Pi-MP3_Player
5 stars 0 forks source link

Pi-MP3 and Radio Stream Player

Pi-MP3_Player

Note this will work under BUSTER, BULLSEYE , OR BOOKWORM

Note tested on a Pi5 with bookworm but not a PI 7" screen.

Designed to be used with a Pi and the Pi 7" Touchscreen LCD, but will work on other monitors. Playing .mp3, .flac, .wav, .dsf, .m4a tracks from USB sticks (or HDD) under /media/pi/usb_stick_name/artist name/album_name/tracks.

You could put MP3 track files on the SD card under /home/USERNAME/Music, and put the tracks in an appropriate directory eg. /home/USERNAME/Music/Rolling Stones/Exile on Mainstreet/. NOTE MP3 ONLY (and your username may not be pi).

Default playlist name etc are definable in the script. Avoid any directory/track names with [ ] (square brackets) in.

Tested on Pi 2 v1.1, 3A, 3B, 4B, Zero W, v1.2 & v1.3 , Pi400 and Pi4 with 32 and 64bit Pi OS, all using Buster. Also tested on a Pi4 4GB using FULL 32bit and 64bit BULLSEYE & BOOKWORM

For Radio Stream use Pi3, Pi4, Pi5 or Pi400 recommended as it requires RAM space.

See installation_instructions.txt for how to install and run.

LCD Screenshots

screenshot

To install

Download the Zip, Extract, and copy MP3_Player.py, mp3c.py and mp3.jpg to /home/USERNAME/

and then run...

sudo apt-get install python3-alsaaudio

sudo apt-get install mplayer

sudo pip3 install mutagen (with BOOKWORM add --break-system-packages)

sudo pip3 install mplayer.py (with BOOKWORM add --break-system-packages)

sudo apt-get install streamripper

sudo apt-get install python3-pil.imagetk

sudo pip3 install rpi_backlight (with BOOKWORM add --break-system-packages)

To run python3 MP3_Player.py

To run at boot (assuming booting to GUI) if using Buster, Bullseye or Bookworm using X11. ..

add @/usr/bin/python3 /home/pi/MP3_Player.py to the end of /etc/xdg/lxsession/LXDE-pi/autostart

( replace pi with your login username)

File structure

On the USB sticks the format must be /Artist Name/Album Name/Track Name so in File Manager you will see the Tracks...

Note that my USB stick was called JUKEBOX but maybe called something like 0845-A56E or 31 GB Volume, there is no need to name / rename it.

You can add images of the album covers in the album directories for displaying, name ending in .jpg MAX size 218 x 218 pixels.

File structure Screenshot

screenshot

New features

You could also add track names to other tracks, for example a recorded session with multiple tracks, by adding a .txt file in the album directory with the same name as the track.

Format: Track start time text

000:01 Introduction

001:50 Track Name 1

006:23 Track Name 2

I use the analog audio output on the 3.5mm 4way socket. Bluetooth may work BUT I found it kept dropping out.

The default playlist is stored in /home/pi/Documents/ALLTracks.m3u with the following format...

/media/pi/JUKEBOX/Roxy Music/For Your Pleasure/01 Do The Strand.mp3

/media/pi/JUKEBOX/Roxy Music/For Your Pleasure/02 Beauty Queen.mp3

in this case JUKEBOX is the name of the USB stick.

If you don't have a /home/pi/Documents/ALLTracks.m3u file when you start the script it will generate one from the tracks it finds on the USB stick(s).

You can put, or use the script to generate, other .m3u files in the /home/pi/Documents/ directory and they can be accessed using the P-List buttons. Remember to include the full path to the tracks in them.

Clicking on 'RELOAD ALLTracks' will make a new ALLTracks.m3u playlist from the USB stick(s). Use this if you add or remove tracks to/from the USB stick, or insert another USB stick.

You can PLAY, PAUSE or STOP Tracks (remember to Stop BEFORE closing the script or click QUIT or SHUTDOWN ), Shuffle ON/OFF, Repeat ON/OFF, Change to A-Z Artist/Album/Track track order, switch to next / previous Artist, Album or Track.

'Repeat ON' will constant repeat the playlist.

Clicking 'next A-Z' will step through the artists/albums/tracks from A to Z, showing the first one for each letter. To select other Artists/Albums/Tracks with the same starting letter use ARTIST/ALBUM/TRACK >.

You can also generate .m3u files. Choose the artist, album or track from ALLTracks.m3u ( or other m3u playlist when you have more), enter a name for the .m3u list (if you don't it will make a name based on date & time), then press either 'ADD track to .m3u' , 'ADD album to .m3u' or 'ADD artist to .m3u'. Repeat process to add more tracks, albums or artists. Click 'STOP' to clear .m3u field. You can now access the new playlist with the P-list buttons.

'ADD P-List to .m3u' will allow you to make larger .m3us from other m3us, or you can DELETE a .m3u file, enter the name and press the 'DEL .m3u' button. Note you CANNOT DELETE the ALLTrack.m3u or ADD it to another list.

You can also set a SLEEP period and the pi will shutdown after that, or SHUTDOWN will shutdown immediately, unless you are recording Radio.

You can add images of the album covers in the album directories for displaying, name ending in .jpg MAX size 218 x 218 pixels.

You can add images of the Radio Stations in /home/pi/Documents for displaying, name ending in .jpg MAX size 218 x 218 pixels.

==========================================================================

To install Download the Zip, Extract, and copy MP3_Player.py, mp3c.py and mp3.jpg to /home/pi/

and then run...

sudo apt-get install python3-alsaaudio

sudo apt-get install mplayer

sudo pip3 install mutagen

sudo pip3 install mplayer.py

sudo apt-get install streamripper

If you see ImportError: cannot import name 'ImageTk' from 'PIL' (/usr/lib/python3/dist-packages/PIL/init.py)

then sudo apt-get install python3-pil.imagetk

To run python3 MP3_Player.py

To get the script to run at boot, assuming you are booting to the GUI

add the following line to /etc/xdg/lxsession/LXDE-pi/autostart

@/home/pi/myscript.sh

and make a file called myscript.sh containing

!/bin/bash

sleep 10 /usr/bin/python3 /home/pi/MP3_Player.py

and make it executable with sudo chmod +x myscript.sh