Skip to content
Advertisement

Custom Audio Player in react JS – Volume Control

I am building an custom audio player in React JS, I am current stuck with the volume controls in the audio player

Here is my code

Progress bar works fine, What should be logic behind the volume control

JavaScript

AduioPlayer.js

JavaScript

changeRange function :

JavaScript

changePlayerCurrentTime function :

JavaScript

Advertisement

Answer

Audio HTML Elements have a volume property you can access. You will need to have an onChange event in your audio slider.

Something like this within your onChange method will work:

audioPlayer.current.volume = e.target.value / 100;

where e is the ChangeEvent passed into the onChange method.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement