Html5音频标签 - 在一个功能中一起播放()和暂停()

时间:2011-12-02 11:20:33

标签: jquery html5

我正在开发一款老虎机游戏。我有播放()和暂停()音频的问题。

旋转的javascript函数

function spin(){
//This is to play the music each time the spin() function called
document.getElementById('myMusicFile').play();
</* spin start code ... reel animations display*/>
// the below code is used to stop the audio after 4sec of spinning
setTimeout(function(){ 
     document.getElementById('myMusicFile').pause();
}, 4000);
}

HTML音频标签是:

<audio id="myMusicFile" preload="auto" autobuffer loop="loop"> 
  <source src="music/reel.ogg" type="audio/ogg" /> 
  <source src="music/reel.mp3" type="audio/mp3" /> 
  Your browser does not support the audio tag.
</audio>  

这适用于Google Chrome。但是在Firefox中,它可以用于每个备用旋转。在safari中有点奇怪..有时候它会播放4秒......有时它会在iPhone和Safari浏览器之间停止播放。

在firefox和safari中..如果我尝试播放并暂停作为按钮,其功能play()和pause()工作正常。

因此,对旋转按钮一起执行play()和pause()时会出现问题。 请建议我解决这个问题的方法!或者提供一些工作样本或资源来解决这个问题。

提前致谢。

1 个答案:

答案 0 :(得分:0)

使用一些标志。开始比赛时举起你的旗帜。如果您的旗帜已经启动,请不要重新开始。当你停止/暂停时,它就下来了。任何布尔变量都可以工作。

相关问题