Show the current time of the video, instead of the remaining time on videojs
Asked Answered
T

3

19

I use VideoJS, a HTML5 video player

By default it displays the remaining time (countdown) instead of the normal current time (like youtube)

Any ideas how to "fix" it? You can see a live example at their official website

Telles answered 10/3, 2013 at 15:43 Comment(0)
E
47

For other people that search for a solution...

All timers exist on the player but by default the current-time, time-divider and the duration info are hidden with display: none;.

So the only thing we have to do is hide the remaining-time and show the time-control which includes the current-time, time-divider and the duration.

The solution in CSS code that should work with your player:

.video-js .vjs-time-control {
    display: block;
}
.video-js .vjs-remaining-time {
    display: none;
}

player-with-time-control

The documentation does not explain this, or to be precise it fails to explain it when it explains how to customize your player with CSS.


Fast html code snippet:

<style type="text/css">
    .video-js .vjs-time-control{display: block;}
    .video-js .vjs-remaining-time{display: none;}
</style>
Exieexigency answered 4/6, 2017 at 2:30 Comment(3)
For me, instead of changing .vjs-time-control, I changed .vjs-current-time, which solved my problemSplurge
It displays vjs-time-control however, there is no time on it: "/"Cailean
I can not believe it that we have to hack the DOM elements visibility to do this :/Silkaline
U
6

easy way is change default ControlBar.prototype.options

ControlBar.prototype.options_ = {
  children: ['playToggle', 'volumePanel', 'currentTimeDisplay', 'timeDivider', 'durationDisplay', 'progressControl', 'liveDisplay', 'remainingTimeDisplay', 'customControlSpacer', 'playbackRateMenuButton', 'chaptersButton', 'descriptionsButton', 'subsCapsButton', 'audioTrackButton', 'fullscreenToggle']
};

change to

ControlBar.prototype.options_ = {
  loadEvent: 'play',
  children: ['playToggle', 'volumeMenuButton', 'currentTimeDisplay', 'progressControl', 'liveDisplay', 'durationDisplay', 'customControlSpacer', 'playbackRateMenuButton', 'chaptersButton', 'subtitlesButton', 'captionsButton', 'fullscreenToggle']
};

final display time control

<style type="text/css">
    .video-js .vjs-time-control{display:block;}
</style>

result: https://i.sstatic.net/7Vvxm.png

Ulpian answered 16/10, 2017 at 7:55 Comment(1)
new versions can refer to this answer: #45727517Tapp
B
0

Relevant as of July 2024.
I found a way to display the current time.
First, download the styles https://vjs.zencdn.net/8.12.0/video-js.css to your local machine.

Around line 1479, you will see:

.vjs-live .vjs-time-control,
.vjs-live .vjs-time-divider,
.video-js .vjs-current-time,
.video-js .vjs-duration {
  display: none;
}

You need to comment out one line:

.vjs-live .vjs-time-control,
.vjs-live .vjs-time-divider,
/*.video-js .vjs-current-time,*/
.video-js .vjs-duration {
  display: none;
}

Replace the library stylesheet link from the Internet with the local stylesheet in your HTML page.

You can remove the remaining time like this:

let videoPlayer = videojs(videoElem, {
    controls: true,
    controlBar: {
        remainingTimeDisplay: false
    }
});

Profit!

Barrelhouse answered 11/7, 2024 at 17:38 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.