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

Global Jukebox API functions

I have added  playJukeboxPlaylist([listid]) and  stopJukeboxPlaylist() functions in my custom API script. However, I am not getting any response. Has something changed? I thought perhaps perhaps I was not reading the viable ids from the Campaign() object to pass to the playJukeboxPlaylist() function; however, adding log() functions to verify and even when hard-coding a known value, there is still no response. Further the stopJukeboxPlaylist() does not stop the music when initiated from the UI. Suggestions?
1597346247
The Aaron
Roll20 Production Team
API Scripter
Can you post the lines where you call these functions?
1597347271

Edited 1597347495
Dj
Pro
Excerpt from API this.parseCmd = function(item, index) { var arg = item["commandText"].trim().split(' '); log("--"+item["commandText"]); switch (arg[0].toLowerCase()) { case _cmdPLAYSXLIST: // !enchantR --playsxlist listName var valid = this.validateArgs(arg,1, "Usage => !enchantR --playsxlist [listName]"); if (!valid) {break;} var listName = ""; var listId = ""; for(i=1;i<arg.length;i++) { listName += arg[i]+" "; } responseOut = "/w GM Invalid Playlist"; var folders = JSON.parse(Campaign().get('_jukeboxfolder')); for (var p in folders) { if(folders[p]['n'] && folders[p]['n'].toLowerCase() === listName.toLowerCase().trim()) { listId = folders[p]['id']; } } if (listId.length>0) { playJukeboxPlaylist(listId); } else { stopJukeboxPlaylist(); } log("playList = "+listId); if (listId.length>0) { responseOut = "/w GM Starting Playlist: "+listName; } log("--leaving sync call"); this.output.push({"speakAs":this.speakAs,"response":responseOut}); item["processed"]=true; break; case _cmdSTOPSOUND: // !enchantR --stopsound var sxTracks = findObjs({ _type: 'jukeboxtrack', }); _.each(sxTracks, track => { var trackObj = JSON.parse(JSON.stringify(track)); log(trackObj.title + ": playing = "+trackObj.playing+", softstop = "+ trackObj.softstop); if (trackObj.playing) { log("Playing: " + trackObj.title+ " ["+trackObj._id+"]"); var trackPlay = getObj("jukeboxtrack", trackObj._id) trackPlay.set({playing:false,softstop:true,loop:false}); } }); stopJukeboxPlaylist(); log("--leaving sync call"); this.output.push({"speakAs":this.speakAs,"response":"/w GM Stopping Music"}); item["processed"]=true; break; ... } }
1597372359

Edited 1597373055
Victor B.
Pro
Sheet Author
API Scripter
The Aaron will reduce this code down (feel free The Aaron, I'd like to see it), but this is what Roll20AM is doing.           var lists        = JSON.parse(Campaign().get('jukeboxfolder'));         _.each(lists,list=>{             if (list.n != undefined){                 _.each(list.i,(t)=>{                     track =  getJukeBox(t) getJukeBox = function(trackID){     return getObj('jukeboxtrack',trackID); },  
So, instead of using the  playJukeboxPlaylist()  function, I should iterate the tracks of the list and play them consecutively. But what's the point of having "shuffle" mode if it will be forced to play in order (or I add a randomizer).
1597377407
Victor B.
Pro
Sheet Author
API Scripter
I have a shuffle routine that shuffles the tracks and then plays them. If you want and a randomized routine on list.i and then play that in order
1597378431

Edited 1597378776
Victor B.
Pro
Sheet Author
API Scripter
You can recreate a wheel if you want.  It's fun.  Or you can install Roll20AM.  Import your tracks into Roll20AM.  Using the menus set your playlist to random or shuffle.  Within your API, do a sendchat sending the following command: !roll20AM --audio,play|<playlistname> and you'll be golden
Thanks. I can check it out. However, I'd still like to know why the global function is not working.
1597465204
Victor B.
Pro
Sheet Author
API Scripter
Alright, instead of this:  listId = folders[p]['id']; try this listId = folders[p]['i'];
Thanks for the catch on the array element. Nonetheless, it still doesn't explain why the function didn't work when I hard-coded the I'd from a confirmed value. I rewrote that loop several different ways, using the log function to iterate the output. At the end of the day, calling neither the  playJukeboxPlaylist(argument)  nor stopJukeboxPlaylist() worked. And I just would like to confirm they still work.  Long story short, I solved it with your original suggestion and added on('change:jukeboxtrack") handler to iterate through the track items. It was fun, as you said.  What ai should probably do is isolate the problem as a single script and confirm the functions still fail to work. Thanks for the review and catching my code typo. 
1597470733
Victor B.
Pro
Sheet Author
API Scripter
Nice.