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

Still cannot get sound API to play sound.

1444090209

Edited 1444090361
DXWarlock
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
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
Pro
API Scripter
Great!  I'd been meaning to try it out, but hadn't gotten to it yet.
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.
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: /*************************************************************************** &nbsp;* Designed by <a href="mailto:josh.vannuys@gmail.com" rel="nofollow">josh.vannuys@gmail.com</a> &nbsp;* <a href="https://app.roll20.net/users/110325/joshua-v" rel="nofollow">https://app.roll20.net/users/110325/joshua-v</a> &nbsp;* &nbsp;* This API accepts the arguments trackName and trackLength (in &nbsp;* milliseconds) and then determines if the track named is included in the &nbsp;* campaign. If it is already playing it is stopped. Then the track is &nbsp;* played normally. The track is stopped after it's play time. This prevents &nbsp;* the issue with the sound playing again at the next startup. &nbsp;* &nbsp;***************************************************************************/ function playTrack(trackName, trackLength) { &nbsp; &nbsp; if (state.debug) log("Attempting to play track " + trackName); &nbsp; &nbsp; delay = 20; //in ms &nbsp; &nbsp; var track = findObjs({ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type: 'jukeboxtrack', &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; title: trackName &nbsp; &nbsp; &nbsp; &nbsp; })[0]; &nbsp; &nbsp; if (state.debug) log(track); &nbsp; &nbsp; if (state.debug) log('is currently playing: ' + track.get("playing")); &nbsp; &nbsp; if (track.get('playing') === true) { &nbsp; &nbsp; &nbsp; &nbsp; if (state.debug) log("stopping and starting track"); &nbsp; &nbsp; &nbsp; &nbsp; track.set('playing', false); &nbsp; &nbsp; &nbsp; &nbsp; track.set('softstop',false); &nbsp; &nbsp; &nbsp; &nbsp; setTimeout(function() { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; track.set('playing', true); &nbsp; &nbsp; &nbsp; &nbsp; }, delay); &nbsp; &nbsp; } else if (track) { &nbsp; &nbsp; &nbsp; &nbsp; if (state.debug) log("starting track"); &nbsp; &nbsp; &nbsp; &nbsp; track.set('playing', true); &nbsp; &nbsp; } else { &nbsp; &nbsp; &nbsp; &nbsp; log("No track found"); &nbsp; &nbsp; &nbsp; &nbsp; return; &nbsp; &nbsp; } &nbsp; &nbsp; setTimeout(function() { &nbsp; &nbsp; &nbsp; &nbsp; if (state.debug) log("stopping track"); &nbsp; &nbsp; &nbsp; &nbsp; track.set('playing', false); &nbsp; &nbsp; &nbsp; &nbsp; track.set('softstop',false); &nbsp; &nbsp; }, trackLength); }
Im confused as to how this works ;d
1445826946
DXWarlock
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
Pro
API Scripter
Saevar, you might be confused because this is part of a script, not a script at all. &nbsp;It is a discussion of how to get sounds playing in other scripts.
Is there a such a script yet?
1445956442

Edited 1445956586
DXWarlock
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() { &nbsp; &nbsp; PlaySound('Explosion'); }); function PlaySound(trackname, time) { &nbsp; &nbsp; var track = findObjs({type: 'jukeboxtrack', title: trackname})[0]; &nbsp; &nbsp; track.set('playing',false); &nbsp; &nbsp; track.set('softstop',false); &nbsp; &nbsp; if(track) { &nbsp; &nbsp; &nbsp; &nbsp; track.set('playing',true); &nbsp; &nbsp; } &nbsp; &nbsp; else { &nbsp; &nbsp; &nbsp; &nbsp; log("No track found"); &nbsp; &nbsp; } }