如何检测音频已在网页中播放完毕? [英] How to detect an audio has finished playing in a web page?

查看:30
本文介绍了如何检测音频已在网页中播放完毕?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我需要将音频(例如:mp3 等)嵌入到网页中.当用户访问页面时,音频将开始播放.音频结束后,会出现问卷(表单域)供用户回答.

In my project, I need to embed audio (ex: mp3, etc) into a web page. When user visits the page, the audio will begin playing. When the audio ends, the questionnaire (form fields) will appear for the user to answer.

有没有办法用jquery检查音频是否播放完毕,让用户听完整个音频后出现问卷?

Is there is way to check if the audio has finished playing using jquery, so that the questionnaire can appear after the user has listened to the entire audio?

我知道一种检查方法是确定音频长度,然后我可以设置一个计时器来显示调查问卷,但我希望 jquery 具有某种允许我完成此操作的事件处理程序.

I know one way to check is to determine the audio length, then I can set a timer to display the questionnaire, but I'm hoping jquery has some sort of event handler that allows me to accomplish this.

我看到 jquery 有很多音频插件,我不能确定哪个能在这里做我想要的:http://plugins.jquery.com/plugin-tags/audio

I see that jquery has many audio plugins, and I can't be sure which will do what I want here: http://plugins.jquery.com/plugin-tags/audio

非常感谢任何想法.

谢谢.

推荐答案

如果您使用 html5 音频标签,则有onended"事件处理程序.不知道浏览器是否支持.

If you are using the html5 audio tag, there is the "onended" event handler. I don´t know if the browsers support it yet.

类似于:

<audio src="xpto.mp3" onended="DoSomething();"></audio>

在最后一种情况下,您可以使用可以播放声音的 swf,并在播放结束时提醒您的 javascript.

In the last case you can use a swf that can play the sound, and alert your javascript when it reaches the end.

这篇关于如何检测音频已在网页中播放完毕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆