我有4个音频文件,我需要它们以某种顺序播放,但在某种程度上它们只能在之前播放时播放 - 一个接一个播放。
这是我的尝试
"use strict"
var sound0 = new Audio("https://s3.amazonaws.com/freecodecamp/simonSound1.mp3");
var sound1 = new Audio("https://s3.amazonaws.com/freecodecamp/simonSound2.mp3");
var sound2 = new Audio("https://s3.amazonaws.com/freecodecamp/simonSound3.mp3");
var sound3 = new Audio("https://s3.amazonaws.com/freecodecamp/simonSound4.mp3");
var a = [0, 1, 2, 3];
function play1() {
for (let i = 0; i < a.length; i++) {
if (a[i] === 0) {
sound0.play();
} else if (a[i] === 1) {
sound1.play();
} else if (a[i] === 2) {
sound2.play();
} else if (a[i] === 3) {
sound3.play();
}
}
};
&#13;
<div>
<button id="playBtn" onclick="play1()">Play</button>
</div>
&#13;