Thank you for your donation!


Cloudsmith graciously provides open-source package management and distribution for our project.


Solved: Hardware Button to select next streaming radio channel
#1
Greetings from BC, Canada!

Here is what I am trying to accomplish:

- have the player start playing a streaming station taken from a list of favorite stations that I can manage via the web interface.
- use a GPIO button to select the 'next' streaming station in the playlist.
- when I get to the end of the playlist, I want the next button push to select the first station again.

I have been able to open my Favourites folder, manually add a number of stations to the queue, and use the 'next track' button on the GUI to select the next streaming station. One issue is that when I press next track enough times, I get to the end of the queue and I cannot get back to the first station in the queue.

My ultimate goal would be to have a playlist automatically added to the queue on startup, or reloaded when a hardware button is pressed if possible.

Could anyone point me in the right direction?

I know a bit of Python - enough to be dangerous, but the way.

Cheers,
Brian
Reply
#2
1. Familiarize yourself with mpc options.
Code:
mpc help

2. Use the GPIO Button Handler to execute commands or scripts when hardware buttons are pressed.

I'm not able to repro "I get to the end of the queue and I cannot get back to the first station in the queue.". When I'm playing the last item in the Queue and click Next the first item in the Queue starts playing.
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#3
(02-11-2022, 08:12 PM)Tim Curtis Wrote: 1. Familiarize yourself with mpc options.
Code:
mpc help

2. Use the GPIO Button Handler to execute commands or scripts when hardware buttons are pressed.

I'm not able to repro "I get to the end of the queue and I cannot get back to the first station in the queue.". When I'm playing the last item in the Queue and click Next the first item in the Queue starts playing.

Thanks for the fededback. I was trying to get the button handler to trigger some basic actions, but not having luck. Is there some formatting I need to kn ow about when setting a command to execute on button GPIO triggering?
Reply
#4
From the help

Code:
NOTE: Use a comma to delimit arguments in the CMD field. Example: mpc,load,My Playlist
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#5
I forgot to mention that if you have multiple commands to execute they will need to be placed in a script. The CMD field in the button handler should contain the absolute path to the script. In the example below that path would be /home/pi/myscript.sh

Example

Code:
# Open the nano editor
sudo nano /home/pi/myscript.sh

# Enter the text below
#!/bin/bash
mpc stop
mpc clear
mpc load MyPlaylist
mpc play

# Save the file
Ctrl-x Y return

# Mark the script executable
sudo chmod +x /home/pi/myscript.sh
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#6
(02-11-2022, 08:45 PM)Tim Curtis Wrote: From the help

Code:
NOTE: Use a comma to delimit arguments in the CMD field. Example: mpc,load,My Playlist

Thanks, Tim. I saw that. I am able to get the 'next' command to work, but if I try to load a playlist, that doesn't seem to work.

One last question - can the GPIO command field accept multiple commands? If not, I presume there is a way to point the GPIO to a script.
Reply
#7
Tim:

My last question had crossed over with your answer - thanks a bunch.
Reply


Forum Jump: