how to: push buttons for web radio stations

Hi,

i’m building a standalone music player powered by volumio running on the raspi zero. The device should be controllable without smartphone or PC, so it has to be possible to change volume, press play/pause, prev/next song and playing the favourite radio station or playlist by pressing push buttons or turning rotary encoders. The rotarty encoder plugin will be used to change volume, toggle play/pause (short press) and shutdown the pi (long press). It seams that there was no solution to play my favorite radio stations by pressing a button. I used the official GPIO buttons plugin to implement this feature:

  1. play your favourite radio, connect to your Pi via ssh an type
volumio status
  1. copy albumart path and the uri path to a text file on your PC

  2. Edit the GPIO buttons plugin file “/data/plugins/system_controller/gpio-buttons/index.js”

sudo nano /data/plugins/system_controller/gpio-buttons/index.js
  1. As i use the rotary encoder as described above, we can edit the code for volume change, play/pause and shutdown. So i can play four different radio station by clicking the buttons. As an example, i used the volume down function:
//Volume down
GPIOButtons.prototype.volumeDown = function() {
  //this.logger.info('GPIO-Buttons: Vol- button pressed\n');
  socket.emit('pause');
  socket.emit('clearQueue');
  socket.emit('addPlay', {'service':'webradio','title':'RADIO BOB!','uri':'http://bob.hoerradar.de/radiobob....837424','albumart':'http://cdn.../logoq.png'});
  socket.emit('play');
};
  1. Go to the GPIO buttons plugin settings in the UI and select the GPIO according to the function you just changed

Note: you can also use http://volumio.local/dev/ to extract the uri and the albumart path

References/used links:
https://forum.volumio.org/station-keys-for-web-radio-t6675.html
https://forum.volumio.org/empty-the-play-queue-via-websocket-t9216.html
https://volumio.github.io/docs/API/WebSocket_APIs.html

I hope this helps some of you :smiley:

-Alex

2 Likes

Thanks for sharing.