哪个Javascript函数可以同时播放多个音频?
Which Javascript function can be used to play more than one audio simultaneously?
我正在考虑Moodly.site
我可以添加一个音频并且可以让用户点击播放它但是如何使 1+ 音频成为 played.I 我不确定,我可以只用 Vanilla JS 来制作它还是我需要使用任何框架。
HTML 中是否有任何标签可以让我这样做,或者它只是 JS 的一部分?
var a1 = document.getElementById("a1");
var a2 = document.getElementById("a2");
var b1 = document.getElementById("b1");
var b2 = document.getElementById("b2");
b1.addEventListener("click", function () {
a1.play();
});
b2.addEventListener("click", function () {
a2.play();
});
<audio id="a1" src="https://www.learningcontainer.com/wp-content/uploads/2020/02/Kalimba.mp3">
Your browser does not support the
<code>audio</code> element.
</audio>
<audio id="a2" src="https://www.learningcontainer.com/wp-content/uploads/2020/02/Kalimba.mp3">
Your browser does not support the
<code>audio</code> element.
</audio>
<button id="b1">1</button>
<button id="b2">2</button>
确保更改音频文件
Edit: added buttons-js
我正在考虑Moodly.site 我可以添加一个音频并且可以让用户点击播放它但是如何使 1+ 音频成为 played.I 我不确定,我可以只用 Vanilla JS 来制作它还是我需要使用任何框架。
HTML 中是否有任何标签可以让我这样做,或者它只是 JS 的一部分?
var a1 = document.getElementById("a1");
var a2 = document.getElementById("a2");
var b1 = document.getElementById("b1");
var b2 = document.getElementById("b2");
b1.addEventListener("click", function () {
a1.play();
});
b2.addEventListener("click", function () {
a2.play();
});
<audio id="a1" src="https://www.learningcontainer.com/wp-content/uploads/2020/02/Kalimba.mp3">
Your browser does not support the
<code>audio</code> element.
</audio>
<audio id="a2" src="https://www.learningcontainer.com/wp-content/uploads/2020/02/Kalimba.mp3">
Your browser does not support the
<code>audio</code> element.
</audio>
<button id="b1">1</button>
<button id="b2">2</button>
确保更改音频文件
Edit: added buttons-
js