I am using php to generate javascript that creates and plays sounds
like:
$playsound .= "var $sound = new Audio('http://$siteurl/sounds/$sound.ogg'); soundplayer($sound $whentostart, $whentostop); ";
soundplayer is a javascript function that takes the sound name, and durations of when to start and stop as parameters.
The problem I have is I have groups of soundplayer(with params) that I want to play together…ie certain groups play sounds at the same time. Then other groups that I need to start at some interval after.
For example:
This group plays:
soundplayer(with params)
soundplayer(with params)
Some time between say 1 to 4 seconds
Then this group plays:
soundplayer(with params)
soundplayer(with params)
then repeat for as many groups
What can I do in either jquery or javascript to wrap each function call to soundplayer() groups to get each group to play with specific intervals in between?
You can do that with either
setTimeout(chaining) orsetInterval(which repeats until you stop it).In JavaScript, and conceptually, to keep things simple:
That’s the
setIntervalversion. ThesetTimeoutversion just involvesdoThingsInOrdercalling itself viasetTimeoutat the end: