Random album play

Hello,
I’m very happy I found Volumio, very cool project! The only thing missing for me is random album play feature - it would be great for guys like me who like playing albums from start to end, but have huge library and would like to be surprised :wink: .

I’m a junior dev myself (work in C# though), could someone give me pointers for queue manipulation if I wanted to write some sort of plugin?

Thanks!

1 Like

Take a look at ‘Guides’. Adding random tracks to queue.

Hola,

I had the same need and made a script in python for this. Now a button in my remote control plays a random album.

#/usr/bin/python

from socketIO_client import SocketIO, LoggingNamespace
import random

sock=SocketIO('localhost', 3000)

def on_browse_library(*args):
    #print(args)
    discos=args[0]['navigation']['lists'][0]['items']
    disco=discos[random.randint(0,len(discos)-1)]['uri']
    sock.emit('clearQueue')
    sock.emit('addToQueue', {'uri':disco})
    #the next lines suck, but work...
    sock.wait_for_callbacks(seconds=1)
    sock.emit('play',0)
    sock.wait_for_callbacks(seconds=1)
    sock.emit('toggle')
    
        
sock.on('pushBrowseLibrary',on_browse_library)

sock.emit("browseLibrary", {'uri': 'albums://'}, on_browse_library)
sock.wait_for_callbacks(seconds=1)

You’ll need to install the socketIO library first:
sudo pip install socketIO-client

1 Like

This requires code changes? Do you have binary for this?

Got it working now after creating a Python script. Thanks a lot. What is your solution for remote control on Volumio?

Hi, just yesterday I got around to changing my script from loading the first track of 25 random albums to loading a random track from each of the 25 random albums.
I don’t think it would pass any awards for programming… but it works.

// library2queue

function rand(max, min) {
        return Math.floor(Math.random() * (+max - +min)) + min;
}

var i = 0;
var tracks = 0;
var io = require('socket.io-client');
var socket = io.connect('http://localhost:3000');
socket.emit(’stop’);
socket.emit('clearQueue');
('browseLibrary', {'uri':'albums://'});
socket.on('pushBrowseLibrary',function(data) {
  item = data.navigation.lists[0].items[0];
  if (item.type == 'song') {
    try {
      while (item.type == 'song') {
        item = data.navigation.lists[0].items[i];
        i++;
      }
    }
    catch(err) {
      i-- ;
      tracks = rand(i, 0);
      item = data.navigation.lists[0].items[tracks];
      i = 0;
    }
    socket.emit('addToQueue', {'uri':item.uri});
  } else {
     var list = data.navigation.lists[0].items;
     var random = rand(list.length - 1, 0);
     select = list[random];
     socket.emit('browseLibrary', {'uri':select.uri});
  }
});

socket.on('pushQueue', function(data) {
      if (data.length > 25) {
            socket.emit("play",{"value":0});
            socket.disconnect()
      } else {
            socket.emit('browseLibrary', {'uri':'albums://'});
      }
});

setTimeout(function() { socket.disconnect(); }, 10000);

I’m glad it helped :slight_smile:

I use a hacky solution: my amplifier’s remote has some useless buttons, so I figured I could use these for volumio.

I read the remote with an ir reader and an arduino plugged into the old netbook running volumio.

Then I made a small bash script reading the input from the arduino and running mostly CLI commands for volumio. For the more complex tasks like playing a random album it calls a python script.

Finally I made a service starting the script with volumio.

Now my son can play his favorite album with just one button :slight_smile:

Bash script:

#!/bin/sh

while read -r line </dev/ttyACM0; do
  if [ "$line" = "5EA1F906" ]; then
# boton btanterior
volumio previous
  elif [ "$line" = "5EA17986" ]; then
#boton btsiguiente
volumio next
  elif [ "$line" = "5EA139C6" ]; then
#boton btplaypause
volumio toggle
  elif [ "$line" = "9E616A95" ]; then
#boton stop
volumio clear
  elif [ "$line" = "9E6140BF" ]; then
#boton joaquin
volumio clear
python home/fernando/joaquin.py
  elif [ "$line" = "9E61F20D" ]; then
#boton disco al azar
python home/fernando/discoalazar.py
  elif [ "$line" = "9E6120DF" ]; then
#boton disco boxtops
python home/fernando/joaquin_boxtops.py
  fi
done

Service:

[Unit]
Description=servicio para usar los botones libres de yamaha para volumio
Arter=network.target
After=local-fs-pre.target

[Service]
Type=oneshot
User=volumio
ExecStart=/bin/bash /usr/bin/remoto.sh

[Install]
WantedBy=multi-user.target
1 Like

Thanks for the solution. But i guess it is too adventurous for me :relaxed:. I am fine using the CL for now.