Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

258
Views
how to play a video from a specific startTime to a specific endTime
<video id='vsingle' src='test.mp4' poster='poster.jpg' controls></video>

<p class='story' data-start=5>lorem ipsum</p>
<p class='story' data-start=10>dolor sit</p>

var vid = document.getElementById("vsingle");

$('.story').on('click', function(){
  let x = $(this).attr('data-start');
  vid.currentTime=x;
  vid.play();
});

the above works fine - i.e. video starts from x
now I need to add endTime - something like this:

<p class='story' data-start=5 data-end=10>lorem ipsum</p>

$('.story').on('click', function(){
  let x = $(this).attr('data-start');
  let y = $(this).attr('data-end');
  vid.currentTime=x;
  vid.endTime = y;
  vid.play();  // from `x` to `y`
});

how to set the endTime and play the video from x to y ?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Start HTML5 video at a particular position when loading?

You can check this post, i am adding an example below:

<video id='vsingle' src='https://assets.mixkit.co/videos/preview/mixkit-girl-crying-and-screaming-heartbroken-42253-large.mp4' poster='poster.jpg' controls></video>

<p class='story' data-start=5>lorem ipsum</p>
<p class='story' data-start=10>dolor sit</p>
const vid = document.querySelector("#vsingle");

$('.story').on('click', function(){
  let x = $(this).attr('data-start');
  let y = $(this).attr('data-start');

  vid.currentTime=x;
  vid.play();

  video.addEventListener("progress", function(){
  if(video.currentTime >= y){
    video.pause();  
  }
}, false);
});

!Alternate!: Also You can add the url parameter:

const vid = document.querySelector("#vsingle");
const url = vid.getAttribute('src')

$('.story').on('click', function(){
  let x = $(this).attr('data-start');
  let y = $(this).attr('data-end');

  vid.setAttribute('src', `${url}#t=${x},${y}`);
  vid.play();
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!