rajaa
rajaa

Reputation: 49

play a videojs from a given position

I use videojs as player and I want if I restart the video for the second time to start reading from the last position before leaving it the last time

avant quitter le player je stocke la position

whereYouAt = player.currentTime();
var currentTime = localStorage.currentTime;
localStorage.currentTime = whereYouAt;

to restart it

playFilmVideo=function()
{

    if (player.readyState() < 1) {

        player.one("loadedmetadata", onLoadedMetadata);

    }
    else {
        // metadata already loaded
        onLoadedMetadata(); 

    }
}
function onLoadedMetadata() {

                var weAreAt = localStorage.currentTime;

                    var dri = weAreAt.split(".");
                    var LastTime= dri[0];
                player.currentTime(LastTime);

 }

when I launch the application for the first time the player starts reading from the position last.but when I leave the player without leaving the application and relaunch it again it starts reading from the beginning of the video

knowing that localStorage.currentTime is still recovering the last position

Upvotes: 2

Views: 3440

Answers (2)

rajaa
rajaa

Reputation: 49

My solution is to remove the fuction readyState() and it worked well:

player.on('loadedmetadata', function(msg) {

        player.play();
        onLoadedMetadata();

        });

function onLoadedMetadata() {

                var weAreAt = localStorage.currentTime;

                    var dri = weAreAt.split(".");
                    var LastTime= dri[0];
                player.currentTime(LastTime);

 }

Upvotes: 1

Amit Bhoyar
Amit Bhoyar

Reputation: 1057

you can set/seek current time of video on load using following snippet.

myPlayer.currentTime(120); // 2 minutes into the video

ref - docs

Upvotes: 1

Related Questions