While I have been able to listen for the "timeupdate" event with a vanilla HTML5 player, I can't seem to get it to work with video.js.
Here's my code:
<!DOCTYPE html>
<html>
<head>
<link href="video-js.css" rel="stylesheet">
<script src="video.js"></script>
<script src="jquery.min.js"></script>
</head>
<body>
<video id="testvid" class="video-js vjs-default-skin" controls width="640" height="480" data-setup='{}'>
<source src="testvideo.mp4" type="video/mp4">
</video>
</body>
</html>
<script>
videojs('testvid').ready(function(){
var myPlayer = this;
$(myPlayer).bind('timeupdate', function(){
console.log('the time was updated to: ' + this.currentTime);
});
});
</script>
Am I misunderstanding a basic way that video.js operates?
The timeupdate event is fired when the time indicated by the currentTime attribute has been updated. The event frequency is dependent on the system load, but will be thrown between about 4Hz and 66Hz (assuming the event handlers don't take longer than 250ms to run).
js. A JavaScript library that allows developers to programmatically control video and audio within IFrames across a number of services. Publishers can also expose a JavaScript API for developers to build rich applications with their media.
js setup methods are used to initialize a video. var myPlayer = videojs('example_video_1'); In the following example, the data-setup attribute tells the Video. js library to create a player instance when the library is ready.
The timeupdate event occurs when the playing position of an audio/video has changed. This event is invoked by: Playing the audio/video. Moving the playback position (like when the user fast forwards to a different point in the audio/video)
You actually CAN register events in callback of ready(), and it is better solution because in previous one registration of event still could be finished after ready(). Use following snippet:
videojs('example_video_1').ready(function () {
this.on('timeupdate', function () {
console.log(this.currentTime());
})
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With