I'm very much new to javascript and am in fact using it as part of an R program. I would like to be able to stop any sounds from playing each time this new sound-making function is called. One user on the forum suggested that this could be done by storing the audio instance in global, possibly in an array, and then calling stop on it. However, as a complete novice user, I've done some searching and was not able to work out how to store to global.
My idea for this function would be that each time it is called, it first stops any current snd instances from playing, and then stores the new instance in global so that it can also be stopped if another sound function is played. Does anyone have an idea of the code that would achieve this?
shinyjs.soundmaker = function() { # wrapper for an R function
var snd = new Audio("data:audio/wav;base64,blablablabla");
snd.play();
}
Even my friend posted on stackoverflow but didn't get any solution. So posted on this community and also it was one of my R Interview Questions.