0

我目前正在使用以下方式在我的网站上播放音效。每次从从设备收到协议时,我都需要播放声音:

<script>
function RxProtocol()
{
    playSound('audio123.wav');
}

function playSound(soundfile) 
{
    document.getElementById("dummy").innerHTML=
    "<embed src=\""+soundfile+"\" hidden=\"true\" autostart=\"true\" loop=\"false\" />";
}
</script>

<body>
<span id="dummy"></span>
</body>

但似乎这样播放的音频每次都会延迟。在我收到我的协议 2 秒后,只播放了音频。

是因为我没有预加载音频吗?你们能教我如何修改我的代码并使其成为预加载启用吗?

4

2 回答 2

0

Somehow my below coding worked for firefox and chrome but not for IE9:

<script>
function RxProtocol()
 {
    var a = document.getElementById("audio1");
    a.play();
 }

</script>

<body>
<audio id="audio1">
<source src="audio.wav" type="audio/wav">
<source src="audio.mp3" type="audio/mpeg">
audio tag not supported.
</audio>
</body>

After trying and trying, I found out that I need to put the below in order for IE9 to work. Firefox and Chrome worked too:

<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

Before this, I put the below coding which worked on Firefox and Chrome only:

 <meta http-equiv="Pragma" content="no-cache"/>

Do you guys know what is the difference of these two meta?

于 2013-05-06T09:25:52.260 回答
0

你可以preload attribute试试html5 audio tag

喜欢preload="auto"

还阅读http://webdesignledger.com/tips/audio-and-video-with-html5http://code.google.com/p/html5-preloader/

于 2013-05-06T08:12:13.937 回答