gpt4 book ai didi

html - 播放 HTML 中的音频文件列表

转载 作者:行者123 更新时间:2023-12-02 23:53:14 24 4
gpt4 key购买 nike

我有三个音频文件(audio1.mp3, audio2.mp3 and audio3.mp3)

我要玩audio1.mp3首先,完成后audio2.mp3需要立即启动(即无需用户交互),最后 audio3.mp3audio2.mp3 之后完成的。
audio1.mp3 --> audio2.mp3 --> audio3.mp3
在当前浏览器中实现此行为的最佳方法是什么?

最好不使用任何插件(Flash、Java 等) - Javascript 库(例如 jQuery)很好

最佳答案

您可以像这样使用 HTML 5 音频标签

<audio id="player" controls autoplay>
<source src="audio1.mp3" type="audio/mpeg">
</audio>

这将自动播放第一首歌曲。

然后可以绑定(bind)播放器的 ended像这样使用 javascript 的事件
var audio = $("#player")
audio.addEventListener('ended',function(){
audio.src = "new url";// you can probably load this from an array of songs URL that you can maintain
audio.pause();
audio.load();
audio.play();
});

这将在播放器中加载新网址并自动播放下一首歌曲。

检查这些链接以获取更多信息
link1 link2

additional example

关于html - 播放 HTML 中的音频文件列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21171332/

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