Advertisement Create a free account

Still cannot get sound API to play sound.

1444090209

Edited 1444090361
DXWarlock
Pro
Sheet Author
API Scripter
Ive tried everything I can think of..and it logs correctly. but I nor anyone else can hear the sound playing. here is the code Im testing with: on("ready", function() {     PlaySound('Headshot', 9000) }); function PlaySound(trackname, time) {     var track = findObjs({type: 'jukeboxtrack', title: trackname})[0];     track.set('playing',false);     log(track);     if(track) {         track.set('playing',true);         log('playing');         setTimeout(function() {track.set('playing',false);log('stopping sound');}, time);         log(track);     }     else {         log("No track found");     } } and the debug I get {"_type":"jukeboxtrack","_id":"-K-0CQvOha0HA0uWI8YO","playing":false,"softstop":true,"title":"Headshot","loop":false,"volume":100} "playing" {"_type":"jukeboxtrack","_id":"-K-0CQvOha0HA0uWI8YO","playing":true,"softstop":true,"title":"Headshot","loop":false,"volume":100} "stopping sound" Which is all correct. Its logging the song as not playing. logs starting it, logs it as playing..then 9 seconds later stopping it. Whats really weird if I play it from the jukebox manually, SOMETIMES a save will play it once after that, but not again, and not all the time. I cant figure it out. Any tips?
1444161185
DXWarlock
Pro
Sheet Author
API Scripter
i FINALLY figured it out..was the 'softstop' option. I have to set it to false each play to get it to play.  changing it to this function PlaySound(trackname, time) {     var track = findObjs({type: 'jukeboxtrack', title: trackname})[0];     track.set('playing',false); track.set('softstop',false); .... works fine. :)
1444163350

Edited 1444163360
The Aaron
Forum Champion
API Scripter
Great!  I'd been meaning to try it out, but hadn't gotten to it yet.
1445348570
Thanks for finding this. I too was having the same issue and didn't realize there was a softstop attribute. I could get my sounds to play a few times, but it seemed to hangup forever if it coinsided with another sound triggering. I would have to remove that specific sound and re-add to get the API to work. Adding this softstop has fixed that.
1445353608
Update - I thought this was working, but it's not doing the trick for all of my sounds. I get the feeling that when I trigger a play of a specific track when another track, say in the playlist, is switching over that there is an issue. But sometimes a track just won't play again. At least I'm not having the issue I was with the track I really built the API for: /***************************************************************************  * Designed by josh.vannuys@gmail.com  * https://app.roll20.net/users/110325/joshua-v  *  * This API accepts the arguments trackName and trackLength (in  * milliseconds) and then determines if the track named is included in the  * campaign. If it is already playing it is stopped. Then the track is  * played normally. The track is stopped after it's play time. This prevents  * the issue with the sound playing again at the next startup.  *  ***************************************************************************/ function playTrack(trackName, trackLength) {     if (state.debug) log("Attempting to play track " + trackName);     delay = 20; //in ms     var track = findObjs({             type: 'jukeboxtrack',             title: trackName         })[0];     if (state.debug) log(track);     if (state.debug) log('is currently playing: ' + track.get("playing"));     if (track.get('playing') === true) {         if (state.debug) log("stopping and starting track");         track.set('playing', false);         track.set('softstop',false);         setTimeout(function() {             track.set('playing', true);         }, delay);     } else if (track) {         if (state.debug) log("starting track");         track.set('playing', true);     } else {         log("No track found");         return;     }     setTimeout(function() {         if (state.debug) log("stopping track");         track.set('playing', false);         track.set('softstop',false);     }, trackLength); }
Im confused as to how this works ;d
1445826946
DXWarlock
Pro
Sheet Author
API Scripter
Saevar L. "Liquid-Sonic" said: Im confused as to how this works ;d Confused on how it is able to work, as in its totally wrong? one of those "I have no idea how this is working, it shouldnt"
Pretty much all of that! From what I took away from the scripts within this thread, was that you can have a sound play on words that filter through the chat? etc?
1445951901
The Aaron
Forum Champion
API Scripter
Saevar, you might be confused because this is part of a script, not a script at all.  It is a discussion of how to get sounds playing in other scripts.
Is there a such a script yet?
1445956442

Edited 1445956586
DXWarlock
Pro
Sheet Author
API Scripter
Saevar L. "Liquid-Sonic" said: Pretty much all of that! From what I took away from the scripts within this thread, was that you can have a sound play on words that filter through the chat? etc? Ah, yea its to trigger sound with a function. Call call it however you want. In OnChat, tokenmove, etc with: PlaySound('Trackname'); Probably not the cleanest or fanciest way it could be done, but it works for what I need it to. For example this is the function I'm using, and an on ready to play a sound when API starts. on("ready", function() {     PlaySound('Explosion'); }); function PlaySound(trackname, time) {     var track = findObjs({type: 'jukeboxtrack', title: trackname})[0];     track.set('playing',false);     track.set('softstop',false);     if(track) {         track.set('playing',true);     }     else {         log("No track found");     } }