简体   繁体   English

从特定点停止播放视频

[英]Stop and play video from specific point

Lets say I have a video and I want to stop it at certain place and leave here a message. 可以说我有一个视频,我想在某个地方停下来并在此处留言。

For example if time was 4.282 , then I want to show message exactly at this time 4.282 .: 例如,如果时间为4.282 ,那么我想在此时精确显示消息4.282

$("video").on("timeupdate",
    function(event){ if(video.currentTime == 4.282) { showMessage(); }
);

Hovewer video.currentTime updates time much rarely than it can catch the time. Hovewer video.currentTime更新时间很少,无法捕捉时间。 For example console.log(video.currentTime) will show: 例如console.log(video.currentTime)将显示:

0.15
0.66
1.12
etc

Also I tried with setInterval, but it's still not accurate enough. 我也尝试了setInterval,但是它仍然不够准确。

I've made it! 我做到了!

First you have to set timeInterval when video plays. 首先,您必须在视频播放时设置timeInterval。

    setInterval( function() {
        var tim = video.currentTime.toFixed(2);
        var timi = tim+0.01;
        if(tim == messageTime || timi == messageTime ) { showMessage(); }
        return tim;
    }, 20);

This will give you video time updates much more precisely. 这将使您更精确地更新视频时间。 You will get something like this: 您将获得如下内容:

1.02
1.04
1.06
etc.

So now it will be much easier to catch the result. 因此,现在将更容易获得结果。 Hovewer sometimes then you will play video from different time it may become: 有时候,您可能会在不同的时间播放视频:

1.01
1.03

So don't forget to add your tim variable +0.01 that will guarantee you will catch all messages. 因此,请不要忘记添加tim变量+0.01,这将确保您能够捕获所有消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM