Tips: how to fast forward a video by 10 seconds

Question of the day: “How can I create a button that will move the video 10s forward”?

Answer: using buttons and a Custom Script Converter

XP can be downloaded here.

Script used (please be indulgent, a “real” JS developer could probably do a better job here):
Note: the binding converter INPUT is the “current time” property of the video, having the format 00:01:23.123456

Script for +10s or +30s buttons

var h = parseInt(INPUT.substr(0, 2));
var m = parseInt(INPUT.substr(3, 2));
var s = parseInt(INPUT.substr(6, 2));

s += 10;
if (s >= 60) {
  s -= 60;
  m += 1;
  if (m >= 60) {
    m -= 60;
    h += 1;
  }
}

var formattedS = ("0" + s).slice(-2);
var formattedM = ("0" + m).slice(-2);
var formattedH = ("0" + h).slice(-2);

formattedH + ":" + formattedM + ":" + formattedS

Script for -10s or -30s buttons (formulas are different)

var h = parseInt(INPUT.substr(0, 2));
var m = parseInt(INPUT.substr(3, 2));
var s = parseInt(INPUT.substr(6, 2));

s -= 10;
if (s < 0) {
  if (h == 0 && m == 0) {
    s = 0;
  } else {
    s += 60;
    m -= 1;
    if (m < 0) {
      m += 60;
      h -= 1;
    }
  }    
}

var formattedS = ("0" + s).slice(-2);
var formattedM = ("0" + m).slice(-2);
var formattedH = ("0" + h).slice(-2);

formattedH + ":" + formattedM + ":" + formattedS
4 Likes

Very smart! I like it. Although I’m still new to JS, I could actually make (a little bit!) sense of this. :smiley:

1 Like