javascript - 检测页面上的Flowplayer并添加事件监听器

标签 javascript jquery event-handling jquery-events flowplayer

我正在使用html5media库,对于不支持视频标签的浏览器,它会自动将页面上的 HTML5 视频标签替换为 Flowplayer Flash 播放器。这种情况发生在 IE 和一些旧版浏览器上。

我需要检测页面上是否存在 Flowplayer,并向每个实例添加一个事件监听器,以便在用户开始播放视频时触发 JavaScript 函数。这可以通过 jQuery 实现吗? Flowplayer 的 Player 对象的 API 描述为 here ;一些例子:

/* 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");
});

如何将 onStart 事件的事件监听器附加到 Flowplayer 的每个实例(如果页面上存在)?

最佳答案

这应该可以通过在此处描述的 configureFlowplayer 回调中设置处理程序来实现:http://wiki.github.com/etianen/html5media/custom-flash-players

它最终应该看起来像这样,其中 config 参数是他们用来配置 flowplayer 的东西。我尚未测试此代码,但这应该让您了解需要做什么:

<script>
html5media.configureFlowplayer = function(tag, element, config) {
    config.onStart = function(){alert("playing");}
}
</script>

关于javascript - 检测页面上的Flowplayer并添加事件监听器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3085533/

相关文章:

javascript - 使用 AngularJs 在 firebase 中创建用户

javascript - 如何在加载后更新页面?

javascript - 如何在 Aurelia 中使用 aurelia-dialog 插件?

user-interface - Haskell 中实现了哪些事件驱动的应用程序?

javascript - 单击时删除 event.preventDefault 不起作用

javascript - 我如何使用 Chart.js 中的对象键迭代或从数组中获取所有对象

javascript - 为什么 $ ('a.current' ).parent ('li' ).addClass ('current' );不管用?

php - 使用ajax从php多次返回

php - 有类似的用于绘制图表(如 Google Charts)的库/类吗?

java - 使用 jtable 生成表运行时和鼠标单击事件