从 video.js 获取当前时间

Get currentTime from video.js

我正在使用文档来获取我的视频的当前时间,但当我执行控制台日志时它只输出 0,这很有意义,因为当我页面加载时视频位于 0有没有一种方法可以让我喜欢看时间,如果我暂停它或在结束时获得视频时间?

我问我的原因是我试图抽出时间来监控我的用户是否真的看完了它并且我之前没有使用过这个库:

<video id="videoPlayer" class="video-js vjs-default-skin vjs-controls-enabled" poster="http://camendesign.com/code/video_for_everybody/poster.jpg" data-setup="{}" controls="">
    <source src="sample.mp4" type="video/mp4">
    <p class="vjs-no-js">Javascript was disabled or not supported</p>
</video>


<script type="text/javascript">

var myPlayer = videojs('videoPlayer');

    var whereYouAt = myPlayer.currentTime();
        console.log(whereYouAt);

</script>

console.log 给我 0

使用timeupdate事件

Fired when the current playback position has changed * During playback this is fired every 15-250 milliseconds, depending on the playback technology in use.

var myPlayer = videojs('videoPlayer');
myPlayer.on('timeupdate', function() {
  console.log(this.currentTime());
});