简体   繁体   中英

Windows phone 8.1 Sound effects javascript

I am creating a small game for windows 8.1 with Javascript and HTML5. I am having a small problem, on click I would like to play a sound, here is the code which I have written.

var sfx_click = new Audio("/Sfx/jump.ogg");
sfx_click.volume = 1;
sfx_click.play();

The above piece of code is not playing the sound. I even tried with Sound.js, createjs.Sound.play("/Sfx/jump.ogg", createjs.Sound.INTERUPT_ANY);

Which did not work. I would like to know what I might be missing here. I have even tried changing the format to .mp3 Should I enable anything in appmanifest?? Any suggestion is really appreciated.

Try to append the sfx_click audio the body of your page.

var sfx_click = new Audio();
document.body.appendChild(sfx_click);
sfx_click.src = "/Sfx/jump.ogg";
sfx_click.play();

The code above works fine in IE with mp3 files. I haven´t tested it with ogg files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM