简体   繁体   English

HTML5音频Javascript循环,但是

[英]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? 此当前配置会播放并循环播放“ 1530.mp3”,它是否也应该播放并循环播放“ 1507.mp3”吗? 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). 您在同一元素上设置了两次源,导致它仅播放第二个源(1530.mp3),因为它将覆盖第一个源(1507.mp3)。

You need two audio elements to play two files. 您需要两个音频元素才能播放两个文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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