Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Help with Jukebox API Script

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?
1465184836
Lithl
Pro
Sheet Author
API Scripter
Campaign().get('jukeboxfolder') should give you the information you need to determine playlists.
1465215188

Edited 1465215251
Thanks, Brian. I am using Campaign().get('jukeboxfolder') to get the list of playlists, but I don't think it shows which one is currently playing: [{ "i": ["-KDzx6CMfz_auZ_wGuXc", "-KDzxCBsMDIRlDNo-Irc"], "n": "Tense", "id": "-KDzqfJXtSoovMwQbvpJ", "s": "b" }, { "i": ["-KDzqk_ZfmiqzK_fYjOl", "-KDzrv9Cj4SqOIcNgz8E"], "n": "Exploring", "id": "-KDzqdsfupjP155WNMKQ", "s": "b" }, { "i": ["-KDzqz_ZS2r3hMG2IURL", "-KDzrPXxRWdsUbvPSfDp"], "n": "Combat", "id": "-KDzqYmhHhV3QoERcOdF", "s": "s" }] I'm assuming "i" is for "items" inside the folder? "n" is name, "id" is self explanantory and "s" is "Play Mode" with the value "b" representing "back to back" and "s" being shuffle. When I grabbed this via Campaign().get('jukeboxfolder'), the "Tense" playlist was playing the first song. Am I missing something? Is there a way to see which playlist is playing? Also, if I do log(getObj("jukeboxtrack", "-KDzx6CMfz_auZ_wGuXc")) immediately after, I get: { "_type": "jukeboxtrack", "_id": "-KDzx6CMfz_auZ_wGuXc", "playing": false, "softstop": false, "title": "Thief Deadly Shadows OST - South Quarter by mandalorclan", "loop": false, "volume": 30 } Even though, according to the UI, that's the track that is playing, it's showing false for "playing." If, via the UI, I stop the jukebox, then start the track individually (not from the playlist), the API shows correctly that the track is playing. So my other idea, of looking for which track is playing and then, ahem, backtracking to the currently playing playlist from there seems to be giving me trouble as well. Any ideas?