Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start video at a given time?

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.

like image 642
Jitendra Avatar asked Dec 12 '17 13:12

Jitendra


People also ask

How do you start a video at a certain time in HTML?

Add ? autoplay=1 to the end of the sharing page link. This URL argument will make the video play automatically when the page loads. If you want the video to start playing at a specific time, also add second=15 to the end of the URL.

Can you link a YouTube video to start at a certain time?

Pause the video where you want the viewer to begin watching the video. Right click within the YouTube video frame. From the right-click menu, select “get video URL at current time.” Now, paste the URL to wherever you are sharing the link.

How do you make a YouTube link start and end at a certain time?

Amending the URL Enter the start and stop times in whole seconds (e.g. one minute and two seconds = 62 seconds) and make sure not to include any additional characters or spaces or it will not work. ? start=67&end=80 When the above is added to the end of the YouTube URL the video will start at 1:07 and stop at 1:20.


1 Answers

I think currentTime is what you want.

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

more about it

like image 61
Hakan SONMEZ Avatar answered Dec 15 '22 20:12

Hakan SONMEZ