FPP Create Randomized list of Playlists from Button Press

FPP Create Randomized list of Playlists from Button Press

I’ve seen a lot of discussion around push-button setups recently, so I thought I’d share how I’ve handled it. I originally adapted the script from FPP7 and updated it for FPP9. 

“This script works well for me, but every setup is different. If you decide to use it, please do so at your own risk—I can’t take responsibility if anything goes wrong. That said, I hope it’s helpful and makes things easier for you too!”

I run everything through playlists. This way, I can number them and reference them easily in the script instead of having to type out full sequence names.

Each playlist can contain one or multiple songs, depending on how you want to structure it.

The button only triggers while my “static” playlist is running during show hours. For example, I have a static playlist called Static During that loops continuously between 16:00 and 20:00. It just holds a static sequence until someone presses the button, which then activates a music playlist. When that music playlist finishes, the system automatically falls back to the static sequence.

The first time the button is pressed, the script randomly generates a list of all available playlists and stores it in a database. It then plays the first music playlist and pushes it to the back of the queue.

Each subsequent press plays the next music playlist in line and again moves it to the back of the queue. This way, everything cycles smoothly without repeats until the list has fully rotated.

One issue I ran into was timing at the end of the night. Since the button was active from 16:00 to 20:00, a press at 19:59 would cut a song off instantly at closing. To fix that, I added a buffer that extends to 20:04 (the maximum runtime of my longest playlist). This ensures that if a song starts close to closing, it’s allowed to finish. If the button is pressed again during this buffer, the system switches to a Static Post playlist that signals the end of the show.

Finally, I set a “Time” value that controls how long the database list remains active. In my case, the show lasts for 3 hours 30 minutes, so I set the value to 240 (4 × 60 minutes). Pressing the button the next day will generate a fresh random playlist order, so it never repeats the exact playlist order from the night before.

Full Code can be found here

Back to blog