feat: logarithmic volume support #9124
Open
+573
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Addresses: #8498
This PR adds support for logarithmic (perceptual) volume control to Video.js, providing a more natural audio experience that better matches human perception of loudness. When enabled via the
logarithmicVolumeoption, the volume slider uses decibel-based scaling where linear slider movements produce logarithmic volume changes, making volume adjustments feel more consistent across the entire range.The Problem:
As discussed in issue #8498, traditional linear volume control doesn't match how humans perceive sound. With linear scaling:
Specific Changes proposed
Logarithmic volume control solves this by using decibel (dB) scaling, the audio engineering standard that matches human hearing perception (source). This implementation provides finer control at lower volumes where precision matters most - the first 50% of the slider covers roughly 0-6% of actual volume. This solution remains fully backward compatible - linear volume remains the default behavior.
Usage:
New
VolumeTransferclass:src/js/utils/volume-transfer.js- Volume transfer functions for converting between slider position and player volumeVolumeTransfer(base class),LinearVolumeTransfer(default, maintains current behavior), andLogarithmicVolumeTransfer(decibel-based scaling)Updates to
VolumeBar:src/js/controls/volume-control/volume-bar.jsinitVolumeTransfer_()to initialize transfer function based onlogarithmicVolumeoptionhandleMouseMove(),getPercent(),stepForward(), andstepBack()to use transfer functionsNew Player Options:
logarithmicVolumeoption (boolean, default: false)Added
logarithmicVolumeRangeoption (number, default: 50)Tests:
test/unit/utils/volume-transfer.test.js- Test suite covering both transfer implementationsTest Page:
https://christriants.github.io/video.js/sandbox/logarithmic-volume.html
Requirements Checklist
npm run docs:apito error