开发者

Playing a sound in Firefox or Chrome

开发者 https://www.devze.com 2023-03-15 17:47 出处:网络
I\'m trying to play a开发者_如何转开发 wav file by ANY means. With the audio tag or not, it does not matter.

I'm trying to play a开发者_如何转开发 wav file by ANY means. With the audio tag or not, it does not matter.

It's for an application only used internally, and the sound only plays when a serious error is made. So it exists to annoy people.

This is the code so far:

var audioElement = document.createElement('audio');
audioElement.setAttribute('src', 'wav/actors_relig1.wav');
audioElement.play();

But that did not work.


I think you need to append the created div first

document.getElementsByTagName('body')[0].appendChild(audioElement);

and wait for it to load with

audioElement.addEventListener('loadeddata', function() {audioElement.play()}, false);

0

精彩评论

暂无评论...
验证码 换一张
取 消