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);