Itay k
Itay k

Reputation: 4471

Mediaelement.js setCurrentTime sets the time incorrectly in Firefox and when using flash

I am using the mediaelement.js component for showing only parts of the video.
I've put a listener on the timeupdate event and Every time the video is playing a segment I wish to skip it jumps to the next segment by using setCurrentTime(). However the next time the timeupdate event is called the time is different then what was set (a few seconds before the time that was set). this is my code:

var curr = t.media.getCurrentTime();
if (curr < segments[i][0]) {
  console.debug(curr.toFixed(1)+' jumping to '+segments[i][0]+' in segment '+i+'      ['+segments[i][0]+','+segments[i][1]+']');
  t.media.setCurrentTime(segments[i][0]);
  return;
}

when I log the current time after the code is executed it shows that the current time was updated correctly (for instance to 19) but when the event is called the next time the current time is wrong (15.3).
It only happens with firefox and when falling back to flash, in chrome it seems to work.
any ideas?

Upvotes: 3

Views: 1481

Answers (1)

Itay k
Itay k

Reputation: 4471

The problem is with the flash fallback. Apparently flash has a problem with the h.264 format and skipping to a specific time. Flash can only jump to keyframes in a H.264 format video and therefore when media element skips to a certain frame the flash player jumps to the nearest keyframe.
the problem can be fixed by setting a keyframe every couple of frame (for instance by using ffmpeg -g flag) but a better solution will be to keep the video in another format for the flash fallback.

Upvotes: 3

Related Questions