JS如何实现音乐播放器只能同时播放一个实例?或者播放时屏蔽其他按钮。
推荐于2016-12-02
展开全部
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
好
<input type="radio" id="hao3" name="myst1" value="小燕子" >小燕子
<input type="radio" id="hao4" name="myst1" value="短信歌" >短信歌
<br><hr>
没
<input type="radio" id="mei2" name="myst2" value="english" >english
<input type="radio" id="mo4" name="myst2" value="圣诞节歌曲短" >圣诞节歌曲短
<br><hr>
<input name="audioBox2" type="button" id="audioBox2" onClick="play2()" value="播放(HTML5)"/>
<script type="text/javascript">
function play2(){
var temp1 = document.getElementsByName("myst1");
var lwtmp1="";
for(var i=0;i<temp1.length;i++)
{
if(temp1[i].checked)
lwtmp1 = temp1[i].value;
}
var temp2 = document.getElementsByName("myst2");
var lwtmp2="";
for(var i=0;i<temp2.length;i++)
{
if(temp2[i].checked)
lwtmp2 = temp2[i].value;
}
var lw1 = "D://sound/"+lwtmp1+".mp3";
var lw2 = "D://sound/"+lwtmp2+".mp3";
var arr = [lw1,lw2,];
var myAudio2 = new Audio();
myAudio2.preload = true;
myAudio2.controls = true;
myAudio2.src = arr.shift();
myAudio2.addEventListener('ended', playEndedHandler2, false);
myAudio2.playbackRate=1;
myAudio2.play();
document.getElementById("audioBox2").appendChild(myAudio2);
myAudio2.loop = false;
function playEndedHandler2(){
myAudio2.src = arr.shift();
myAudio2.playbackRate=2;
myAudio2.play();
console.log(arr.length);
!arr.length && myAudio2.removeEventListener('ended',playEndedHandler2,false);
}
}
</script>
</body>
</html>
给你了一个例子,改一下里面的value值,和lw1,lw2值就可以打开页面播放了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询