简体   繁体   中英

HTML5 audio Javascript looping but

function nextSong() {
    var v30 = 1;
    var v07 = 1;
    var v......[continues]
    var audioPlayer = document.getElementsByTagName('audio')[0];
    if (v07 == '1') {
        audioPlayer.src='wavs/1507.mp3';
        audioPlayer.load();
        audioPlayer.play();
    }
    if (v30 == '1') {
        audioPlayer.src='wavs/1530.mp3';
        audioPlayer.load();
        audioPlayer.play();            
    }
    if (......[continues]
}

This current configuration plays and loops the '1530.mp3', shouldn't it also play and loop '1507.mp3' too? Im open to any new method of doing this, like an array, which i think would be a better option. Just not so sure how to do so.

audioPlayer.src='wavs/1507.mp3';
audioPlayer.src='wavs/1530.mp3';

You are setting the source twice on the same element, which results in it only playing the second source (1530.mp3) as it overwrites the first source (1507.mp3).

You need two audio elements to play two files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM