Getting the current state of the system
Closed this issue · 3 comments
So I have managed to get a simple example up and running using your api but I was wondering if I can grab a players state. Basically I want to cut out what is playing, play a specific playlist then stop it at some point in time and then resume what was playing on the device before I interrupted (could have been off or playing something else)
So far I have this basic module
var SonosDiscovery = require('sonos-discovery');
var discovery = new SonosDiscovery();
var sonos = {};
sonos.alert = function() {
//Grab player(s) state to set back afterward
var player = discovery.getPlayer('kitchen');
player.play();
};
sonos.stop = function() {
//get the saved state and set what was playing before or stop if nothing
var player = discovery.getPlayer('kitchen');
player.pause();
};
module.exports = sonos;
Do you have any examples where you are doing this in the other clients?
Cheers
Hi, yes, the closest I can think of is the say commands from the http-api:
https://github.com/jishi/node-sonos-http-api/blob/master/lib/actions/say.js
basically, check getState() of the player and store the different parameters, then invoking it later on. I have used the preset function to simplify things, although it is still a bit messy.
I'll take a look. Thanks
Also, remember that all actions are asynchronous, and the players becomes very unhappy if you send parallell requests (they only have 4 threads available for http requests), so you need to make sure to run them i series.