How to store (and later stop) a javasript audio instance in a global array

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.

I had a look at that link and it is a load of nonsense. Many of the answers are either wrong or just ill-informed. I would also hope that very few of these would ever crop up in a real interview. If they do, then that would show that the interviewer has little knowledge of the subject.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.