Hello,
I’m currently trying to play with my new remote controller, by binding a playlist / webradio with a specific button.
I have succeeded (quite easily) to bind the button to launch a specific script.
I also have a script (from the forum) to launch a webradio. However, I don’t manage to chain play the newly playlist in the same script.
I have tried several approach.
First: play between the first socket.emit and the socket.on.
socket.emit('addToQueue', {'service':'webradio','title':'France Inter','uri':'http://chai5she.cdn.dvmr.fr/franceinter-midfi.mp3'});
socket.emit('play', '');
socket.on('pushState', function() { socket.disconnect(); } );
Second: emit as a callback of the socket.emit.
socket.emit('addToQueue', {'service':'webradio','title':'France Inter','uri':'http://chai5she.cdn.dvmr.fr/franceinter-midfi.mp3'}, function() {
socket.emit('play', '');});
socket.on('pushState', function() {socket.disconnect(); } );
Third & last: emit as a callback of the socket.on.
socket.emit('addToQueue', {'service':'webradio','title':'France Inter','uri':'http://chai5she.cdn.dvmr.fr/franceinter-midfi.mp3'});
socket.on('pushState', function() {
socket.emit('play', '');
socket.disconnect(); } );[/code]
Here's the full code (with try to play after setting the webradio):
[code]var sys = require('sys')
var exec = require('child_process').exec;
var child;
child = exec("volumio clear", function (error, stdout, stderr) {
sys.print('stdout: ' + stdout);
sys.print('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
var io = require('socket.io-client');
var socket = io.connect('http://localhost:3000');
socket.emit('clearQueue');
var fs = require('fs');
var content = fs.readFileSync('/data/favourites/my-web-radio');
var webradios = JSON.parse(content);
console.log(webradios)
var radio = webradios.find(o => o.name === process.argv[2]);
if (radio == null) {
socket.disconnect();
} else {
socket.emit('addToQueue', {'service':'webradio','title':'France Inter','uri':'http://chai5she.cdn.dvmr.fr/franceinter-midfi.mp3'});
socket.on('pushState', function() { socket.disconnect(); } );
}
});
If you have any idea / hint, I’ll take them with great pleasure!
Best,
Cosmita