Play Music

efore attempting to play your first song, make sure you have successfully installed LightShow Pi and verified your hardware configuration.

Playing your first Song

You can play a single song with the following command from your install directory (replacing the path with that of another music file you’ve uploaded to your Raspberry Pi if desired):

sudo python py/synchronized_lights.py --file=/home/pi/lightshowpi/music/sample/ovenrake_deck-the-halls.mp3

Before the song is played all the lights are turned on for 30 seconds, then off for 1 second before playback begins. You can modify this behavior by overriding the preshow_configuration setting.

Playing back music from a playlist

You can create a playlist of songs to play. The playlist is simply a file with one song per line in the following format (replacing <tab> with the actual <tab> character):

My Cool Song<tab>/home/pi/lightshowpi/music/cool_song.mp3
An Amazing Tune<tab>/home/pi/lightshowpi/music/amazing_tune.mp3

A sample playlist and sample songs are provided in the lightshowpi/music/sample directory.

You can play one song at a time from your playlist by running the following command (replacing /home/pi/lightshowpi/music/sample/.playlist with the path to your playlist):

sudo python py/synchronized_lights.py --playlist=/home/pi/lightshowpi/music/sample/.playlist

Each time the above command is run, a single file from your playlist will be played. To play one song after another from your playlist you’ll want to override the playlist_path configuration setting to point to your playlist, and then run the following script to continuously play songs from your playlist:

start_music_and_lights

To stop the continuous playback, you can issue to following command:

stop_music_and_lights

31 Replies to “Play Music”

  1. Is there a way to convert this simple command line menu to a GUI interface

    #!/bin/bash
    trap ‘ ‘ 2
    while true
    do
    clear
    echo “=================================”
    echo ” Menu of Songs”
    echo “=================================”
    echo “Enter 1 Manheim Steamroller Deck the Halls”
    echo “Enter 2 Frozen”
    echo “Enter 3 Jingle Bells”
    echo “Enter 4 Joy to the World”
    echo “Enter 5 Mary, Did you Know”
    echo “Enter 6 Blue Christmas”
    echo “Enter 7 Main Street Electrical Parade”
    echo “Enter 8 Little Drummer Boy”
    echo “Enter 9 Eye of the Tiger”
    echo “Enter a Don’t want to miss a Thing”
    echo “Enter b Firework”
    echo “Enter q to quit”
    echo -e “n”
    echo -e “Enter your Selection here and hit ”
    read answer # create varible to retain the answer
    case “$answer” in
    1) sudo python py/synchronized_lights.py –file=/home/pi/lightshowpi$
    2) sudo python py/synchronized_lights.py –file=/home/pi/lightshowpi$
    3) sudo python py/synchronized_lights.py –file=/home/pi/lightshowpi$
    4) sudo python py/synchronized_lights.py –file=/home/pi/lightshowpi$
    5) sudo python py/synchronized_lights.py –file=/home/pi/lightshowpi$
    6) sudo python py/synchronized_lights.py –file=/home/pi/lightshowpi$
    7) sudo python py/synchronized_lights.py –file=/home/pi/lightshowpi$
    8) sudo python py/synchronized_lights.py –file=/home/pi/lightshowpi$
    9) sudo python py/synchronized_lights.py –file=/home/pi/lightshowpi$
    a) sudo python py/synchronized_lights.py –file=/home/pi/lightshowpi$
    b) sudo python py/synchronized_lights.py –file=/home/pi/lightshowpi$
    q) exit ;;
    esac
    echo -e “/n”
    echo -e ” Hit the key to continue.. c”
    read input #This cause a pause so we can read the output of the selection be$
    done

    Thanks in advance.

  2. ERROR in execute
    # sudo python py/synchronized_lights.py –playlist=/home/pi/lightshowpi/music/sample/.playlist
    /home/pi/lightshowpi/py/fft.py:61: RuntimeWarning: divide by zero encountered in log10
    :piff(frequency_limits[i][1], chunk_size, sample_rate):1]))

  3. Is there a way to make this work with with a bluetooth adapter with music coming from an external device? I am new to this, but really want to learn more.

  4. Hope you can help. I am getting the following error:

    “Unable to enable V3D. Please check your firmware is up to date.”

    When running [ sudo python py/synchronized_lights.py –file=/home/pi/lightshowpi/music/sample/ovenrake_deck-the-halls.mp3 ]

  5. When I try to set what music I want to play I get an error that “Traceback (most recent call last):
    File ‘py/synchronized_lights.py’, line 465, in
    play_song()
    File ‘py/synchronized_lights.py’, line 290, in play_song
    for song in playlist:
    _csv.Error: line contains NULL byte”
    What does all that mean and how can I fix it?

  6. Is there a way to create 2 playlists and be able to chose between the 2. ie, Halloween and Christmas. So as they year changes, I do not need to use another SD card?

    1. I do this myself, just have two different playlists in two separate directories, then modify your overrides.cfg file to point to one or the other.

  7. just fyi for anyone trying to stream stuff with stream-in mode, don’t just stream the url to stdout with ffmpeg or something, i’ve had better results using these settings and commands:
    (i am streaming theradio.cc)

    1. Run: mkfifo /home/pi/lightshowpi.sock

    2. Change your config to:
    mode = stream-in
    stream_in_command = cat /home/pi/lightshowpi.sock

    3. Start synchronized_lights.py in one terminal (i use tmux)

    4. Run this in another terminal: ffmpeg -re -i http://mp3.theradio.cc -ar 48000 -f wav pipe:1 > /home/pi/lightshowpi.sock

    BOOM! A less resource intensive, less laggy, less delay stream-in mode

  8. Thanks a Ton. I was able to successfully put together the project and the final piece was the software. your code worked like a charm. I am interested to know is there any way to stream the FM as input instead of MP3.

    1. With the current code, you can stream music over the network as input, or from a usb soundcard … so in theory if you have an external FM radio you could pair it with a usb sound card in audio-in mode.

  9. I followed the steps as outlined. However, I receive the following error message when I attempt to utilise the .playlist

    pi@raspberrypi:~/lightshowpi $ sudo python py/synchronized_lights.py –file=/home/pi/lightshowpi/music/Christmas/.Playlist
    Traceback (most recent call last):
    File “py/synchronized_lights.py”, line 965, in
    lightshow.play_song()
    File “py/synchronized_lights.py”, line 805, in play_song
    self.setup_audio()
    File “py/synchronized_lights.py”, line 608, in setup_audio
    self.music_file = decoder.open(self.song_filename, force_header)
    File “/usr/local/lib/python2.7/dist-packages/decoder/__init__.py”, line 735, in open
    raise IOError, (2, “No such file or directory: ‘%s'” % name)
    IOError: [Errno 2] No such file or directory: ‘/home/pi/lightshowpi/music/Christmas/.Playlist’

    1. Verify the file exists there:

      ls -ahlrt /home/pi/lightshowpi/music
      ls -ahrlt /home/pi/lightshowpi/Christmas
      (or should it be christmas lowercase ‘c’)?
      ls -ahlrt /home/pi/lightshowpi/Christmas/.Playlist
      (or should it be .playlist lowercase ‘p’)?

    2. I am having the same issue but the line numbers are different on the message I get
      Did you get yours resolved as Todd has been helping it won’t play the songs I want.

  10. hi, does anyone know why im getting this error while trying to link a music file with lightshowpi as it works well with the sample music files?

    pi@raspberrypi:~/lightshowpi/py $ sudo python synchronized_lights.py –file=/home/pi/Music/Meat_Loaf/Bat_Out_of_Hell.mp3
    Traceback (most recent call last):
    File “synchronized_lights.py”, line 969, in
    lightshow.play_song()
    File “synchronized_lights.py”, line 803, in play_song
    self.setup_audio()
    File “synchronized_lights.py”, line 606, in setup_audio
    self.music_file = decoder.open(self.song_filename, force_header)
    File “/usr/local/lib/python2.7/dist-packages/decoder/__init__.py”, line 735, in open
    raise IOError, (2, “No such file or directory: ‘%s'” % name)
    IOError: [Errno 2] No such file or directory: ‘/home/pi/Music/Meat_Loaf/Bat_Out_of_Hell.mp3’

    The music files appear as,

    pi@raspberrypi:~/Music/Meat Loaf $ dir
    Meat\ Loaf\ -\ Bat\ Out\ of\ Hell.mp3

  11. i have this error when i try to run and no sound come out of it

    Traceback (most recent call last):
    File “py/synchronized_lights.py”, line 979, in
    lightshow.play_song()
    File “py/synchronized_lights.py”, line 810, in play_song
    self.setup_audio()
    File “py/synchronized_lights.py”, line 613, in setup_audio
    self.music_file = decoder.open(self.song_filename, force_header)
    File “/usr/local/lib/python2.7/dist-packages/decoder/__init__.py”, line 771, in open
    wf = fakewave(po, fh)
    File “/usr/local/lib/python2.7/dist-packages/decoder/__init__.py”, line 635, in __init__
    self.initfp()
    File “/usr/local/lib/python2.7/dist-packages/decoder/__init__.py”, line 665, in initfp
    self._nframes = int(self._framerate * info(self.obj.filename).info.length)
    File “/usr/local/lib/python2.7/dist-packages/decoder/fileinfo.py”, line 56, in info
    exec “r = “+mod+”.%s(\”%s\”)” % (func, filename)
    File “”, line 1, in
    AttributeError: ‘module’ object has no attribute ‘Open’

  12. Are there any preset shows? I built a 16 channel controller box and had a friend help me install Lightshow pi after months of asking and failed attempt to do being a 100% beginner and really wanted a show up and running for my 2 year old tomorrow but being told it can’t happen.

Leave a Reply to Todd Giles Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.