I was wondering how to use the state described in the playbackStates documentation. According to the figure, there should be 3 states (playing, stopped, and paused), but the problem in my case is that when I use the PlaybackController’s getState()-method I get a state called pending. Is that another state not included in the state-diagram in the documentation?
I am also wondering how to use the PlaybackState in a node.js application. I want to do something like this:
Mopidy-MusicBox-Webclient uses Mopidy.js to make calls to the Mopidy core. I believe this is the canonical approach for HTTP clients, and may be a good place to start.
Thank you for your replies. The answer provided are about how to use the getState() function, which is something I am doing as well. However, I want to do different things based on the state you are receiving, e.g the state is 'stopped' or 'playing' or anything else. Instead of: if (state === 'stopped') //notice the quotes, the word may change in the future.
I would like to use the state variable which contains the value stopped.
var Mopidy = require("mopidy");
var log=console.log;
var mopidy = new Mopidy({
webSocketUrl: "ws://localhost:6680/mopidy/ws/"
});
mopidy.playback.getState().then(function(state){
log (state);
});
but I get this error:
mopidy.playback.getState().then(function(state){
^
TypeError: Cannot read property 'getState' of undefined
mopidy.playback doesn’t exist before you’re connected to the server. If you wrap your code like this, so it doesn’t run until you’re connected, it should work:
mopidy.on('state:online', function () {
mopidy.playback.getState().then(function (state) {
console.log(state);
});
});