简体   繁体   English

Windows Phone 8.1音效javascript

[英]Windows phone 8.1 Sound effects javascript

I am creating a small game for windows 8.1 with Javascript and HTML5. 我正在使用Javascript和HTML5为Windows 8.1创建一个小型游戏。 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); 我什至尝试使用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?? 我什至尝试将格式更改为.mp3,我应该在appmanifest中启用任何功能吗? Any suggestion is really appreciated. 任何建议都非常感谢。

Try to append the sfx_click audio the body of your page. 尝试将sfx_click音频附加到页面的主体。

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. 上面的代码在带有mp3文件的IE中可以正常工作。 I haven´t tested it with ogg files. 我尚未使用ogg文件对其进行测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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