Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onVolumeChange(e) is called with a SyntheticBaseEvent, but I need new volume #1913

Open
robertlight opened this issue Jan 17, 2025 · 1 comment

Comments

@robertlight
Copy link

robertlight commented Jan 17, 2025

I am playing an mpg url via:

<ReactPlayer className={'react-player'}
           onVolumeChange={handleVolumeChange}     <<<----- THIS SEEMS TO NOT WORK PROPERLY
           ref={inputRange}
           poster={''}
           width='100%'
           height={currentMediaData.type==='audio'?'50px':'100%'}
           url={currentMediaData?.mediaUri}
           pip={pip}
           playing={playing}
           controls={controls}
           light={light}
           loop={loop}
           playbackRate={playbackRate}
           volume={volume}
           muted={muted}
           onReady={() => {
               return 'onReady'
           }}
           onStart={() => setStarted(true)}
           onPlay={handlePlay}
           onBufferEnd={onBufferEnd}
           onPause={() => {
               setPlaying(false);
           }}
           onBuffer={() => {
               setIsBuffering(true);
           }}
           onSeek={e => onSeekTo(e)}
           onError={(e) => onPlayerError(e)}
           onProgress={handleProgress}
           onDuration={handleDuration}
/>

and when onVolumeChanged gets fired when the user changes the volume, it calls 'handleVolumeChange' where the argument is a SyntheticBaseEvent (see image below from webstorm)

I want to get the new volume level so I can update the state variable. Is there another means to get the new volume?

Image
@robertlight robertlight changed the title onVolumeChange(e) is called on volume change but e.target.value is undefined onVolumeChange(e) is called with a SyntheticBaseEvent, but I need new volume Jan 17, 2025
@robertlight
Copy link
Author

I am currently using this HACK within my handleVolumeChange event handler...
setState( {...state,volume: document.getElementsByTagName('audio')[0].volume});

There must be a more elegant 'react-like' method without resorting to document.getElementsByTagName()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant