Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set currentTime in video.js in Safari for iOS

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?

like image 751
zzhxlyc Avatar asked Mar 03 '15 03:03

zzhxlyc


Video Answer


2 Answers

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
like image 127
Avatar Avatar answered Sep 28 '22 23:09

Avatar


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~

like image 20
zzhxlyc Avatar answered Sep 28 '22 21:09

zzhxlyc