我编写了一些代码,用于播放音频(3个或更多音频),每个音频播放多次。我想进行更改,以便可以重新播放所有音频
示例更多说明
我有
音频1然后音频2然后音频3
我现在可以做的是:
音频1将播放3次
音频2将播放3次
audio3将播放3次然后停止
我不想让它停止,我需要让它从头开始再次播放audio1 3次,audio2 3次和audio3 3次很多次,然后停止。
代码在这里:
function startReading(1){
var aCount = 3;
// Start Reading - Play the Audio
// -------------------------------------
var repeatTimes = document.getElementById('repeatA').value;
(function play(c){
audio.play();
audio.onended = function (){
if(c >= repeatTimes ){
if(i <= aCount){//and not reached the last audio
i++;
startReading(i);//play next audio
}
} else {//we didnt reached the third play, lets keep going...
play(c+1);
}
};
})(1)//start with 1
}
最佳答案
我找到了解决方案。
我需要做的是检查i
是否大于音频数量,如果大于音频数量,则从头开始读取并制作i = 1
,并在每次重复所有音频以停止播放chk
时进行检查,如果chk
> (需要多次)。
简而言之,我将使递归从头开始。
代码将是:
var chk = 1;
function startReading(1){
var aCount = 3;
// Start Reading - Play the Audio
// -------------------------------------
var repeatTimes = document.getElementById('repeatA').value;
(function play(c){
audio.play();
audio.onended = function (){
if(c >= repeatTimes ){
if(i <= aCount){//and not reached the last audio
i++;
if(i <= aCount) startReading(i);
else if (repeatTimes > 1 && chk < repeatTimes ){
i = 1;
chk++;
startReading(i);
}
}
} else {//we didnt reached the third play, lets keep going...
play(c+1);
}
};
})(1)//start with 1
}
关于javascript - 使用JavaScript多次播放所有音频后,重复播放多个音频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51196043/