gpt4 book ai didi

jquery - 如何使用 Jquery 制作一个简单的 HTML 播放列表

转载 作者:太空狗 更新时间:2023-10-29 16:35:13 26 4
gpt4 key购买 nike

我需要一些帮助来使用音频 html 标签制作一个非常简单的 Jquery 播放列表。到目前为止,我得到了他的:

<audio id="myAudio" preload="auto">
Your user agent does not support the HTML5 Audio element.
</audio>

和 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>

如何让这 2 个 mp3 一个接一个地播放?感谢您的帮助。

最佳答案

  • 没有要使用 animate 的元素,所以我制作了一个 div#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_mp3
<!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>

关于jquery - 如何使用 Jquery 制作一个简单的 HTML 播放列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35478017/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com