Flowplayer 视频进度跟踪?

发布于 2024-11-29 21:03:59 字数 252 浏览 0 评论 0原文

使用 FlowPlayer API,有没有办法捕获视频进度?我希望捕获视频的进度,以便我可以在视频中的某些点向页面触发事件。在 Flash 中,每帧都会触发 Progress 事件,我希望由于 FlowPlayer 是 Fl​​ash,因此 Progress 事件也能被暴露。我似乎在 FlowPlayer 文档中找不到任何简单的内容。

如果进度事件不存在。对于如何使用 JS setInterval 和现有的 FlowPlayer API 方法构造这样的东西有什么建议吗?

Using the FlowPlayer API, is there a way to capture Video Progress? I'm looking to capture the progress of the video so I can fire events to the page at certain points in the Video. In Flash, there is Progress Event that fires every frame, and I was hoping that since FlowPlayer is Flash, that the Progress Event would also be exposed. I can't seem to find anything as straight-forward in the FlowPlayer docs.

If a Progress Event doesn't exist. Are there any suggestions on how to construct a such a thing using JS setInterval and existing FlowPlayer API methods?

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

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

发布评论

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

评论(2

纵性 2024-12-06 21:03:59

我编写了一段快速的 Javascript 代码片段,它与 Flowplayer PlayerClip 对象交互以确定视频进度。

var videoProgressInterval;

flowplayer("player", "http://releases.flowplayer.org/swf/flowplayer-3.2.15.swf");
flowplayer("player").onStart(startVideoProgressChecking);
flowplayer("player").onResume(startVideoProgressChecking);
flowplayer("player").onStop(stopVideoProgressChecking);
flowplayer("player").onPause(stopVideoProgressChecking);
flowplayer("player").onFinish(stopVideoProgressChecking);

function startVideoProgressChecking() {
    videoProgressInterval = setInterval(checkVideoProgress, 1000);
    videoProgressInterval();
}

function stopVideoProgressChecking() {
    clearInterval(videoProgressInterval);  
}

function checkVideoProgress() {
    var time_completed = flowplayer("player").getTime();
    var total_time = flowplayer("player").getClip().fullDuration;
    var percent_done = Math.floor((time_completed / total_time) * 100);

    console.log(percent_done + "% of video done");
}

您可以在 JSFiddle 上查看演示。

它为播放器的 startresume 事件注册事件句柄。视频播放开始后,它会注册一个每秒运行的间隔(请随意修改此间隔以更频繁地运行)。该间隔每次执行时都会调用 checkVideoProgress(),然后从 Clip 对象获取当前播放时间和总持续时间来计算进度。

此外,还为 stoppausefinish 事件注册了事件处理程序,以便在视频暂停/停止后清除间隔。

I hacked up a quick snippet of Javascript that interacts with the Flowplayer Player and Clip objects to determine the video progress.

var videoProgressInterval;

flowplayer("player", "http://releases.flowplayer.org/swf/flowplayer-3.2.15.swf");
flowplayer("player").onStart(startVideoProgressChecking);
flowplayer("player").onResume(startVideoProgressChecking);
flowplayer("player").onStop(stopVideoProgressChecking);
flowplayer("player").onPause(stopVideoProgressChecking);
flowplayer("player").onFinish(stopVideoProgressChecking);

function startVideoProgressChecking() {
    videoProgressInterval = setInterval(checkVideoProgress, 1000);
    videoProgressInterval();
}

function stopVideoProgressChecking() {
    clearInterval(videoProgressInterval);  
}

function checkVideoProgress() {
    var time_completed = flowplayer("player").getTime();
    var total_time = flowplayer("player").getClip().fullDuration;
    var percent_done = Math.floor((time_completed / total_time) * 100);

    console.log(percent_done + "% of video done");
}

You can see a demo on JSFiddle.

It registers event handles for the start and resume events of the player. Once video playback has begun, it registers an interval which runs every second (feel free to modify this to run more often). The interval calls checkVideoProgress() every time it gets executed which then gets the current playback time and total duration from the Clip object to calculate the progress.

Additionally, an event handler is also registered for stop, pause and finish events to clear the interval once the video has been paused/stopped.

友谊不毕业 2024-12-06 21:03:59

也许您可以使用 Flowplayers Cuepoints

将提示点添加到 data 属性(秒或距离结束的秒数)减号)

<div class="flowplayer" data-cuepoints="[1.5, 2, 3, -1]"><!-- video here --></div>

然后绑定一个事件:

flowplayer(function (api, root) {
    api.bind("cuepoint", function (e, api, cuepoint) {
       console.log(cuepoint);
    });
});

Maybe you can use Flowplayers Cuepoints

Add cuepoints to the data property (either seconds, or seconds from end with a minus)

<div class="flowplayer" data-cuepoints="[1.5, 2, 3, -1]"><!-- video here --></div>

Then bind an event:

flowplayer(function (api, root) {
    api.bind("cuepoint", function (e, api, cuepoint) {
       console.log(cuepoint);
    });
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文