
Hi, I'm writing a script to automate switching playlists. I have a macro I run at the start of combat that runs several other scripts, and I thought it would be nice to wet my feet writing my own Roll20 API scripts by writing something that would switch from whatever the current playlist is to my combat music playlist. Then when I run the script again, it should switch back to the original playlist. Simple. I've found how to start and stop playing playlists by id, and I can start the combat playlist just fine. So far, so good. Next, I figured out how to get a list of playlists from the Campaign object's _jukeboxfolder attribute, but I can't seem to find anywhere that shows the currently playing playlist. My second thought was to check the Page attributes to see if I could find the "Play on Load" playlist, because I make heavy use of that, but that doesn't seem to be exposed via the API either. No problem! I thought I'd use findObjs to get the currently playing track and look through the playlists to find which it belongs to. That's when I found something strange. If I start an individual track using the UI, then the API reports it as playing. If instead I click the play button for the playlist, the individual tracks are not marked as playing in the API even though they are marked as playing in the UI. This is my test code: _.each(findObjs({
"_type": "jukeboxtrack"
}), function(track, idx){
if (track.get('playing')) {
log(idx + ' ' + track.get('title') + ' is playing');
} else {
log(idx + ' ' + track.get('title') + ' is not playing');
}
}); All it does is loop through all the jukebox tracks and print whether or not each track is playing. So I suppose my question is this: how do I find out the currently playing playlist via the API? Or the currently playing track if it was started via a playlist?