Dan Dan - 1 year ago 168
Javascript Question

Get currentTime from video.js

I am using the docs to get the current time of my video but it just outputs

when I do a console log whcih makes sense as when I page load the video is at
is there a way I can like watch the time and if I pause it or at the end get the video time?

the reason why I ask I am trying to get the time to monitor if my users have actually watched it to the end and I have not used this library before:

<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>

<script type="text/javascript">

var myPlayer = videojs('videoPlayer');

var whereYouAt = myPlayer.currentTime();


console.log gives me

Answer Source

Use timeupdate event

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() {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download