0

I'm using Videojs and I need to know when the timeline is used to navigate. Especialy I want the "current time" of the player when I click on the bar, and also the timer where it has been clicked (but easy one, I'll explain)

By using the myPlayer.currentTime() I can get the timer of the video, so I with eventListener such as "onclick" or "onmousedown" I though I can get the timer of the video at the click. But it only give me the timer after.

It's not easy to explain so this is an example : progressbar The timer is currently 0:01, and I click at 0:14 How to get the "0:01" from the player, which event

This is my event but I get the new timer

myPlayer.controlBar.progressControl.on('mouseup', function (event) {
            console.log(myPlayer.currentTime());
});

I even try other event, on other elements such as mousedown which also give me the timer after, and not triggered when I click directly on the slider

myPlayer.controlBar.progressControl.on('mousedown', function (event) {
            console.log(myPlayer.currentTime());
});

I've tried lots of things, none of them work, have you any ideas?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Valoute_GS
  • 25
  • 7

1 Answers1

1

The VideoJS library offers a nifty little event that can be useful for your use-case: timeupdate.

Just set up a global variable previousTime and update it each time the timeupdate event fires. As soon as you click on the progressbar you can get the time via previousTime.

var previousTime;
myPlayer.controlBar.progressControl.on('mousedown', function(event) {
  console.log("previous: " + previousTime + " current:" + myPlayer.currentTime());
});

myPlayer.on("timeupdate", function(e) {
  previousTime = myPlayer.currentTime();
});
obscure
  • 11,916
  • 2
  • 17
  • 36
  • Yes it kind of works but if I click directly on the slider the event is not detected (with mouseup it is , I don't understand why they are about the same, unfortunatly mouseup is triggered to late) – Valoute_GS Jun 24 '19 at 07:14
  • Solution find ! By doing the same on myPlayer.controlBar.progressControl.seekBar Strange tho – Valoute_GS Jun 24 '19 at 07:54