我正在专门为 ipad 创建一个页面。
我在一个页面上有 12 个音频播放器。它们都工作正常,但如果您单击第二个播放器,第一个播放器将继续播放。我以前见过这个问题,但没有一个答案是针对我的代码的。
<script>
function EvalSound(soundobj) {
var thissound=document.getElementById(soundobj);
if (thissound.paused)
thissound.play();
else
thissound.pause();
thissound.currentTime = 0;
}
</script>
玩家自己:
<a href="card3_ipad.php?card=funny" onClick="EvalSound('song1'); return true;"
target="player"><IMG SRC="images/funnytab.gif" BORDER=0 WIDTH=128 HEIGHT=29>
</A>
<audio id="song1" style="display: none; width: 0px; height: 0px;"
src="mp3examples/funnyauto.mp3" controls preload="auto" autobuffer>
那么另一个玩家是:
<a href="card3_ipad.php?card=country" onClick="EvalSound('song2'); return true;"
target="player"><IMG SRC="images/countrytab.gif" BORDER=0 WIDTH=128 HEIGHT=29>
</A>
<audio id="song2" style="display: none; width: 0px; height: 0px;"
src="mp3examples/countryauto.mp3" controls preload="auto" autobuffer>
如有任何帮助,我们将不胜感激!
干杯
汤姆
最佳答案
使用另一个保存当前活跃玩家的变量
<script>
var currentPlayer;
function EvalSound(soundobj) {
var thissound=document.getElementById(soundobj);
if(currentPlayer && currentPlayer != thissound) {
currentPlayer.pause();
}
if (thissound.paused)
thissound.play();
else
thissound.pause();
thissound.currentTime = 0;
currentPlayer = thissound;
}
</script>
关于javascript - 当我单击另一个音频播放器时如何停止播放一个音频播放器 - javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16362317/