js中怎么让音频重复播放
2018-01-07
展开全部
然后这个是主要的js方法:
function Orderprocessing1(){
var vid = document.getElementById("myVideo");//获取音频对象
var start = 0;//定义循环的变量
var times=3;//定于循环的次数
vid.addEventListener("ended",function() {
vid.play();//启动音频,也就是播放
start++;//循环
start == times && vid.pause();//也就是当循环的变量等于次数的时候,就会终止循环并且关掉音频
});
vid.play();//启动音频,用于第一次启动
}
如果你想调用这个方法可以写一个click事件,或者写个js方法调用:
$(function(){
setInterval("Orderprocessing1()",60000);//每隔1分钟自动调用一次启动音频的方法
});
2020-01-26
展开全部
<div class="box">
<audio id="aud" controls="controls">
<source src="Unit 01.mp3" type="audio/mpeg">
</audio>
<button onclick="cltA()" type="button" title="快捷键a">A</button>
<button onclick="cltB()" type="button" title="快捷键b">B</button>
<button onclick="release()" type="button" title="快捷键r">恢复</button>
</div>
A是循环的开始,B是循环结束的地方,按恢复按钮时,会继续播放
<script>
var myAud = document.getElementById("aud");
var start, end, clock;
function cltA() {
if (start == 0) {
start = 0;
} else {
start = myAud.currentTime - 1;
}
}
function cltB() {
end = myAud.currentTime;
if (end - start > 2) {
clearInterval(clock);
let temp = Math.floor((end - start) * 1000);
myAud.currentTime = start;
clock = setInterval(function () {
myAud.currentTime = start;
}, temp);
}
}
function release() {
clearInterval(clock);
myAud.currentTime = end;
}
window.onload = function () {
event = event || window.event;
document.onkeydown = function (event) {
if (event.keyCode == 65) {
cltA();
} else if (event.keyCode == 66) {
cltB();
} else if (event.keyCode == 82) {
release();
} else { }
}
}
</script>
<audio id="aud" controls="controls">
<source src="Unit 01.mp3" type="audio/mpeg">
</audio>
<button onclick="cltA()" type="button" title="快捷键a">A</button>
<button onclick="cltB()" type="button" title="快捷键b">B</button>
<button onclick="release()" type="button" title="快捷键r">恢复</button>
</div>
A是循环的开始,B是循环结束的地方,按恢复按钮时,会继续播放
<script>
var myAud = document.getElementById("aud");
var start, end, clock;
function cltA() {
if (start == 0) {
start = 0;
} else {
start = myAud.currentTime - 1;
}
}
function cltB() {
end = myAud.currentTime;
if (end - start > 2) {
clearInterval(clock);
let temp = Math.floor((end - start) * 1000);
myAud.currentTime = start;
clock = setInterval(function () {
myAud.currentTime = start;
}, temp);
}
}
function release() {
clearInterval(clock);
myAud.currentTime = end;
}
window.onload = function () {
event = event || window.event;
document.onkeydown = function (event) {
if (event.keyCode == 65) {
cltA();
} else if (event.keyCode == 66) {
cltB();
} else if (event.keyCode == 82) {
release();
} else { }
}
}
</script>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询