是否可以在 onMouseover 事件上顺序播放多个声音文件?

发布于 2024-10-13 08:48:27 字数 220 浏览 4 评论 0原文

我知道如何在鼠标悬停事件上一次播放一个声音文件,例如

onMouseover="Playsound(1.wav) 

但是,我想在一个声音文件上依次播放多个声音文件(1.wav、2.wav、3.wav 等)将鼠标悬停在图像或其他元素上。

有可能吗?

提前致谢。

I know how to play a single sound file at a time onMouseover event e.g

onMouseover="Playsound(1.wav) 

However, I want to play multiple soundfiles (1.wav, 2.wav, 3.wav etc) sequentially on a single mouseover either on an image or other element.

Is it possible at all?

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

秋风の叶未落 2024-10-20 08:48:27

如果您知道声音的长度,则可以使用 setTimeout 按顺序播放它们

if you know lengths of the sounds, you can use setTimeout to play them sequentially

梦毁影碎の 2024-10-20 08:48:27

您可以通过将函数附加到鼠标悬停事件来做到这一点,即

element.addEventListener('mouseover',function () {
    Playsound(1.wav);
    /* do stuff ... if you can retrieve 1.wav length you could use, as semyon mentioned, a setTimeout to play other sounds sequentially i.e. .. */
    setTimeout(playanothersoundfn,GetLength(1.wav));
},false)

You could do it by attaching a function to the event mouseover i.e.

element.addEventListener('mouseover',function () {
    Playsound(1.wav);
    /* do stuff ... if you can retrieve 1.wav length you could use, as semyon mentioned, a setTimeout to play other sounds sequentially i.e. .. */
    setTimeout(playanothersoundfn,GetLength(1.wav));
},false)
别再吹冷风 2024-10-20 08:48:27

更好的方法是使用 html5 音频元素并注册一个用于剪辑结束的处理程序:

 <audio src="1.wav" id="first"></audio>
 <audio src="2.wav" id="second"></audio>
 audio = document.getElementById('first');
 audio.addEventListener('ended', function(){
   //play next clip
 });
 audio.play();

setTimeout 不适用于需要精确计时的情况。如果第一个音频剪辑有点滞后,您的 setTimeout 将紧随其后停止。你还依赖上帝知道客户端发生了什么。 :-)

The better way to do it is to use html5 audio element and register a handler for the ending of the clip:

 <audio src="1.wav" id="first"></audio>
 <audio src="2.wav" id="second"></audio>
 audio = document.getElementById('first');
 audio.addEventListener('ended', function(){
   //play next clip
 });
 audio.play();

setTimeout is not great for when precise timing is required. If the first audio clip was a little laggy, your setTimeout will stop on its heels. You are also relying on god knows what is going on at the client. :-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文