Skip to content

Instantly share code, notes, and snippets.

@black--cat
Last active December 16, 2015 18:19
Show Gist options
  • Save black--cat/5476340 to your computer and use it in GitHub Desktop.
Save black--cat/5476340 to your computer and use it in GitHub Desktop.
better solution? I want to observe the playlist for changes. how would i do this without setinterval? In my opinion the best way is to wait for the IPC socket if something happened. Is this possible?
var xmmsclient = require('xmmsclient'),
util = require('util')
var client = new xmmsclient.Client('blackcat');
client.onconnect = function () {
console.log("Connected!")
var oldID
setInterval(function () {
client.playback.current_id().onvalue = function (id) {
if (!oldID || oldID !== id) {
client.medialib.get_info(id).onvalue = function (propdict) {
metadata = xmmsclient.PropDict.flatten(propdict)
console.log("Currently playing " + metadata.artist + " - " + metadata.title)
}
oldID = id
}
}
}, 1000)
}
client.ondisconnect = function () {
console.log("Disconnected!")
}
client.connect("unix:///tmp/xmms-ipc-blackcat")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment