Video.js Playback Rate Adjuster
raw JSON →videojs-playbackrate-adjuster is a Video.js 7 middleware designed to dynamically adjust the displayed duration and current time in the Video.js control bar when the playback rate is changed. For instance, if a 20-minute video is played at 2x speed, the control bar will visually represent it as a 10-minute video, with the progress bar updating proportionally to the adjusted perceived duration. The current stable version is 1.0.1. This library primarily functions as a side-effect plugin, automatically attaching itself to the `videojs` global upon inclusion, without requiring explicit instantiation or assignment. It serves as a specific utility for enhancing the user experience in scenarios where playback speed manipulation is common, ensuring the UI accurately reflects the perceived playback progress rather than the absolute media time. The library's release cadence is not formally defined but typically aligns with compatibility needs for Video.js itself.
Common errors
error ReferenceError: videojs is not defined ↓
video.js script is loaded in your HTML before videojs-playbackrate-adjuster.min.js, or that require('video.js') executes before require('videojs-playbackrate-adjuster') in module environments. error TypeError: player.playbackRate is not a function ↓
player.ready(function() { /* ... */ }); callback to ensure the player is fully initialized and its API methods are available. Warnings
breaking This middleware is specifically designed for Video.js 7.x. Compatibility with older or newer major versions of Video.js is not guaranteed and may lead to unexpected behavior or errors. ↓
gotcha The middleware adjusts only the *displayed* duration and current time in the control bar, not the actual media's properties or playback behavior. The underlying media's duration remains unchanged. ↓
gotcha The library relies on the `videojs` global being available. If `video.js` is not loaded or initialized correctly before `videojs-playbackrate-adjuster`, the middleware will fail to attach. ↓
Install
npm install videojs-playbackrate-adjuster yarn add videojs-playbackrate-adjuster pnpm add videojs-playbackrate-adjuster Imports
- (implicit global effect)
<script src="//path/to/videojs-playbackrate-adjuster.min.js"></script> - (side-effect) wrong
const adjuster = require('videojs-playbackrate-adjuster');correctrequire('videojs-playbackrate-adjuster'); - PlaybackRateAdjuster wrong
import PlaybackRateAdjuster from 'videojs-playbackrate-adjuster';correctconst PlaybackRateAdjuster = require('videojs-playbackrate-adjuster');
Quickstart
// Assume video.js and videojs-playbackrate-adjuster have been loaded via script tags
// or a module bundler, and a Video.js player is initialized on an element with id 'my-video'.
//
// Example HTML setup:
// <video id="my-video" class="video-js" controls preload="auto" width="640" height="264">
// <source src="https://vjs.zencdn.net/v/oceans.mp4" type="video/mp4">
// </video>
// <script src="https://unpkg.com/video.js/dist/video.min.js"></script>
// <script src="https://unpkg.com/videojs-playbackrate-adjuster/dist/videojs-playbackrate-adjuster.min.js"></script>
var player = videojs('my-video');
player.ready(function() {
var myPlayer = this;
console.log('Video.js player is ready. Initial displayed duration:', myPlayer.duration());
// Wait a moment, then change playback rate to observe the effect on the control bar
setTimeout(() => {
myPlayer.playbackRate(2);
console.log('Playback rate set to 2x. Observe how the control bar duration and current time display adjust proportionally.');
// After some time, reset playback rate
setTimeout(() => {
myPlayer.playbackRate(1);
console.log('Playback rate reset to 1x. Control bar display should return to normal.');
}, 5000); // Wait 5 seconds at 2x rate
}, 1000); // Wait 1 second before first rate change
});