fatu
fatu

Reputation: 71

How to impliment currentTime

Im trying to use the currenttime function to make my video.js player play from a specific time.

I've put this directly into the html file but when I open the file in the browser the video is still starting from the beginning. What am I missing?

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"></script>


     <script>
        videojs("example_video_1").ready(function(){
            var myPlayer = videojs.setup("example_video_1");

            // EXAMPLE: Start playing the video.
            myPlayer.currentTime(200);
            myPlayer.play();

        });
  </script>

Edited: to include ending script tag and jquery library...still doesnt work

edit: if you want to see the video.js please download here: http://www.videojs.com/downloads/video-js-4.1.0.zip

Upvotes: 0

Views: 303

Answers (2)

khatzie
khatzie

Reputation: 2569

Try adding event listener.

document.getElementById("myVideo").addEventListener('loadedmetadata', function() {
    this.currentTime = 29;
  }, false);

This works for me.

Upvotes: 1

Cameron Tangney
Cameron Tangney

Reputation: 678

There is no "setup" function in the videojs api. You should check that your video is seekable, and then you should modify your initialization code.

  1. You should make sure that its an issue with video js and not your video file / browser / etc.

    <script>
      var video = document.getElementById("example_video_1");
      video.currentTime = 200;
      video.play();
    </script>
    
  2. If the above works, then the correct way to do what you're trying to do is:

    <script>
      videojs("example_video_1", {}, function() {
        this.currentTime(200);
        this.play();
      });
    </script>
    

Upvotes: 0

Related Questions