DRB
DRB

Reputation: 653

Jump to last frame of video and pause

How do you make a function that goes to the last frame of the video and then pauses? I thought I'd be able to get the duration of the video and then set the time to that and pause/play, but that seems to not work at all.

function goToLast() {
  var vid = document.getElementById("videoID");
  var videoTime = vid.duration;
  vid.currentTime = videoTime;
  vid.pause()
}

Upvotes: 2

Views: 797

Answers (1)

Ares
Ares

Reputation: 1366

From working with videos before I came to the conclusion that frames are not a thing in videos players in JS.

So what you need to do is find what the FPS of the video is (that may not be provided to you unfortunately so you can assume that it's 60 or 30 FPS ) and calculate the time duration that will take you to the next frame.

e.g 1 sec / 60fps = 0.016667 seconds

This is the time interval of a frame.

Then subtract the frame duration from the total duration and you have arrived at the last frame.

So if you total duration is 120 secs then the last frame is 120 - 0.016667

Upvotes: 1

Related Questions