检测页面上的Flowplayer并添加事件监听器
我正在使用 html5media 库,它会自动用 Flowplayer Flash 替换页面上的 HTML5 视频标签适用于不支持 video 标签的浏览器的播放器。这种情况发生在 IE 和一些较旧的浏览器上。
我需要检测页面上是否存在 Flowplayer,并向每个实例添加一个事件侦听器,以便在用户开始播放视频时触发 JavaScript 函数。这可以通过 jQuery 实现吗? Flowplayer 的 Player 对象的 API 在此处进行了描述;一些示例:
/* Set common clip properties and event listeners
* in run-time
*/
// register event listener with common clip
$f("player").onStart(function() {
alert("Playing");
});
// this does the same thing
$f("player").getCommonClip().onStart(function() {
alert("Playing");
});
// if you want to register a listener to a specific clip *only*
$f("player").getClip(1).onStart(function() {
alert("Playing");
});
如果页面上存在 Flowplayer 的每个实例,如何将 onStart
事件的事件侦听器附加到该实例?
I'm using the html5media library, which automatically replaces the HTML5 video tag on the page with the Flowplayer Flash player for browsers that don't support the video tag. This happens on IE and some older browsers.
I need to detect if the Flowplayer exists on the page and add an event listener to each instance that fires off a JavaScript function when the user starts playing a video. Is this possible via jQuery? The Flowplayer's Player object's API is described here; some examples:
/* Set common clip properties and event listeners
* in run-time
*/
// register event listener with common clip
$f("player").onStart(function() {
alert("Playing");
});
// this does the same thing
$f("player").getCommonClip().onStart(function() {
alert("Playing");
});
// if you want to register a listener to a specific clip *only*
$f("player").getClip(1).onStart(function() {
alert("Playing");
});
How do you attach an event listener for the onStart
event to each instance of the Flowplayer, if it exists on the page?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过在此处描述的
configureFlowplayer
回调中设置处理程序应该可以实现:http://wiki.github.com/etianen/html5media/custom-flash-players它最终应该看起来像这样,其中
config
参数是他们的东西用于配置 Flowplayer。我还没有测试过这段代码,但这应该能让您了解需要做什么:It should be possible by setting your handlers up in the
configureFlowplayer
callback described here: http://wiki.github.com/etianen/html5media/custom-flash-playersIt should end up looking something like this where the
config
param is something they are using to configure flowplayer. I have not tested this code, but this should give you an idea of what you need to do: