use*_*956 5 html audio jquery playlist
我需要一些帮助,使用音频html标签制作一个非常简单的Jquery播放列表.到目前为止我得到了他的:
<audio id="myAudio" preload="auto">
Your user agent does not support the HTML5 Audio element.
</audio>
Run Code Online (Sandbox Code Playgroud)
和jquery部分:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script>
$(document).ready(function() {
bgAudio = document.getElementById("myAudio");
bgAudio.volume = 0.3;
bgAudio.controls = true;
bgAudio.loop = true;
bgAudio.autoplay = true;
bgAudio.src = "bg1.mp3";
bgAudio.src = "bg2.mp3";
bgAudio.play();
});
</script>
Run Code Online (Sandbox Code Playgroud)
我该如何让这两个mp3一个接一个播放?谢谢您的帮助.
没有可以使用animateto 的元素,因此我制作了 adiv#bg并将其包裹在音频元素周围。请记住,如果您想让元素以不透明度淡入,请确保该元素以opacity:0
表达式应该是:$('div#bg').animate({opacity: 1}, 1000);
我看了你的问题……现在没有了animate()?
播放列表位于数组中。
该函数player()被调用document ready(所以你不需要autoplay移动设备忽略)
播放器将连续播放每个音频剪辑,并在完成播放列表后重新开始(loop仅适用于一个文件,不适用于播放列表。因此,如果出现这种情况,您将永远不会前进到下一个文件loop=true)
片段
MNG- https://vocaroo.com/media_command.php?media=s0Ai9tr7779v&command=download_mp3
Righteous- https://vocaroo.com/media_command.php?media=s1dKHkbev0dJ&command=download_mp3Run Code Online (Sandbox Code Playgroud)
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>35478017</title>
</head>
<body>
<div id='bg' style="opacity:0">
<audio id="xAudio" preload="auto"></audio>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script>
// This is a simple array of strings
var playlist = [
"https://vocaroo.com/media_command.php?media=s1H9fX5GI9Fa&command=download_mp3",
"https://vocaroo.com/media_command.php?media=s0Ai9tr7779v&command=download_mp3",
"https://vocaroo.com/media_command.php?media=s1dKHkbev0dJ&command=download_mp3"
];
// Remember that element must start out at opacity:0
// The duration should be only a number outside of the curly brackets
$('div#bg').animate({
opacity: 1
}, 1000);
$(document).ready(function() {
var xA = document.getElementById("xAudio");
xA.volume = 0.3;
xA.controls = true;
function player(x) {
var i = 0;
xA.src = playlist[x]; // x is the index number of the playlist array
xA.load(); // use the load method when changing src
xA.play();
xA.onended = function() { // Once the initial file is played it plays the rest of the files
/* This would be better as a 'for' loop */
i++;
if (i > 2) { // ... Repeat
i = 0; // ^
} // ^
xA.src = playlist[i]; // Rinse, ^
xA.load(); // Lather, ^
xA.play(); // and.....^
}
}
player(0); // Call the player() function at 0 index of playlist array
});
</script>
</body>
</html>Run Code Online (Sandbox Code Playgroud)