11

I'm trying to create a clip from a video. which have fixed start and end time. So when I click on the button then the video should start from the given time. Here's my code

  <link href="{{asset('../videojs/videojs-resolution-switcher.css')}}" rel="stylesheet">
  <link href="{{asset('../videojs/video-js.min.css')}}" rel="stylesheet">
  <script src="{{asset('../videojs/video.js')}}"></script>
  <script src="{{asset('../videojs/videojs-resolution-switcher.js')}}"></script>
  <script src="{{asset('../videojs/videojs-offset.min.js')}}"></script> 
  <script src="{{asset('../videojs/Youtube.min.js')}}"></script>

function setSegmentTime(e)
{
    var start_time =  $(e).data("start-time");
    var end_time   =  $(e).data("end-time");

    var myplayer = videojs('demo-video');
    myplayer.offset({
        start: start_time,
        end: end_time,
        restart_beginning: false //Should the video go to the beginning when it ends
    });

    myplayer.play();
}

In this, I have used a plugin for playing a segment of the video but it is also not working. It may be the videojs version issue. https://github.com/cladera/videojs-offset

My question is that, can I play a video at a given time without using above plugin. I have checked everywhere but none of the solution is working. Thanks in advance.

Jitendra
  • 584
  • 1
  • 10
  • 28

1 Answers1

15

I think currentTime is what you want.

// get
var whereYouAt = myPlayer.currentTime();
// set
myPlayer.currentTime(120); // 2 minutes into the video

more about it

Hakan SONMEZ
  • 2,176
  • 2
  • 21
  • 32