7

Other is ok, but the setting of currentTime:

I tried some ways like:

videojs("example_video_1", {}, function() {
    this.currentTime(200);
    this.play();
});

And this is not working.

videojs("example_video_1").ready(function(){
    this.currentTime(200);
});

This also doesn't work.

var dom = document.getElementById('example_video_1');
dom.addEventListener("loadedmetadata", function() {
    dom.currentTime = 100;
}, false);    // ok for no video.js
videojs(dom);

Not working. Even reverse the line of addEventListener and init videojs.

And I tried the videojs event.

var player = videojs("example_video_1");
alert(player.addEvent);
alert(player.addEventListener);

these API all not exists, so how do I bind Event in videojs?

Shashank Agrawal
  • 25,161
  • 11
  • 89
  • 121
zzhxlyc
  • 81
  • 1
  • 1
  • 5

2 Answers2

11

This is how I got the video playback on a defined position at startup (it removes the problem that the video first started and only afterwards jumped to a video position):

$(document).ready(function()
{
    var timecode = 120;
    var initdone = false;

    // wait for video metadata to load, then set time 
    video.on("loadedmetadata", function(){
        video.currentTime(timecode);
    });

    // iPhone/iPad need to play first, then set the time
    // events: https://www.w3.org/TR/html5/embedded-content-0.html#mediaevents
    video.on("canplaythrough", function(){
        if(!initdone)
        {
            video.currentTime(timecode);
            initdone = true;
        }
    });

}); // END ready
Avatar
  • 14,622
  • 9
  • 119
  • 198
1

Oh, by lucky, i found an example in https://github.com/videojs/video.js

var dom = document.getElementById('example_video_1');
videojs(dom, {}, function(){
    this.on('loadedmetadata', function(){
        this.currentTime(500);
    });
});

this is work, the API to bind event is player.on('event', fn);

videojs is cool~

zzhxlyc
  • 81
  • 1
  • 1
  • 5