本文介绍了如何在HTML中播放多个mp3 /歌曲?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让我的网站播放多首mp3 /歌曲,但它一直播放soundtrack1,但我希望它可以同时播放所有3首歌曲。



这是我目前拥有的:

 <音频循环自动播放控制> 
< source src =soundtrack1.mp3type =audio / mpegloop =true>
< source src =soundtrack2.mp3type =audio / mpegloop =true>
< source src =soundtrack3.mp3type =audio / mpegloop =true>
您的浏览器不支持音频元素。
< / audio>


解决方案

所以HTML一样容易1,2,3

 < audio src =...id =song1volume =0.1style =display:none ;>< /音频> 
< audio src =...id =song2volume =0.1style =display:none;>< / audio>
< audio src =...id =song3volume =0.1style =display:none;>< / audio>





<$对于(var i = 1; i< = 3; i ++)
{
document.querySelector(#song+ i)[0] .play,p $ p> ();
}


I'm trying to get my website to play multiple mp3/songs, but it keeps playing soundtrack1, but I want it to play all 3 songs at the same time.

This is what I currently have:

<audio loop autoplay controls>
    <source src="soundtrack1.mp3" type="audio/mpeg" loop="true">
    <source src="soundtrack2.mp3" type="audio/mpeg" loop="true">
    <source src="soundtrack3.mp3" type="audio/mpeg" loop="true">
    Your browser does not support the audio element.
</audio>
解决方案

So the HTML is as easy 1, 2, 3

<audio src="..." id="song1" volume="0.1" style="display: none;"></audio>
<audio src="..." id="song2" volume="0.1" style="display: none;"></audio>
<audio src="..." id="song3" volume="0.1" style="display: none;"></audio>

And the JS magic behind it:

for(var i = 1; i <= 3; i++)
{
    document.querySelector("#song" + i)[0].play();
}

这篇关于如何在HTML中播放多个mp3 /歌曲?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 06:29