angularjs - Why does this Javascript code to play audio needs to have alert() in front to work? -
I would like to play a .wav file on my browser using javascript. The following code does not work;
var audio = new audio ("alert.wav"); audio.play (); However, to make it work, I can do a simple trick by adding a dummy warning () further. alert ("dummy"); var audio = new audio ("alert.wav"); audio.play (); I do not know why this works. My first question is, how can I get the audio to play without that dummy alert ? The second question is that dummy alert () got to do some work? This code was run inside an angulars controller, not sure that this is the case.
OK I think I've discovered the problem I used to do a separate .wav file Tested your code This works fine without the alert box Maybe its either: a) the name of the .wav file is alert (rename the file?) B) This file may be just maybe it is not working, it may be download again (although you can get it Have been) or try a similar sound .wav file? Hope it helps!
Comments
Post a Comment