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

[Video] Add volume slider to video embeds on web #5352

Closed
wants to merge 5 commits into from

Conversation

netux
Copy link

@netux netux commented Sep 15, 2024

Adds an <input type="range"> (better designs are welcome) next to the Toggle Mute button to adjust the volume of the video.

  • The slider defaults to 50% volume.
    This is more a personal preference, but I think not maxing out the volume and blasting people's ears when focus on a video is probably a good idea. 50% is a comfortable default for me.
  • Moving the slider draws focus and unmutes the video. This is inline with other places, like Twitter.
  • The slider is logarithmic, meaning it adjusts better to human perception of sound.
    Basically, with a logarithmic scale, moving the slider from one point to another should feel like the slider value change more accurately resembles the change in volume perceived, even to audiophiles.
    I chose to use the conversion function from this blog post: https://www.dr-lex.be/info-stuff/volumecontrols.html.
  • Volume is applied to all video embeds. This repurposes the video volume state from 843f992.
  • Even has a nice sliding animation, borrowing from YouTube's design.

GIF showcasing the volume slider animation

GIF of user interacting with the new slider and toggle mute button

Resolves #5285

Only for videos on web.
The slider only shows up when the speaker icon is hovered.

- Uses browser's <input type="range"> element
- Starts at 50% (linear for now)
- Unmutes the audio when changed

For convenience, move mute button to new <AudioControls> component.
This aligns better with human perception, so most values in the slider are not practically useless.
Use global video volume context from 843f992

Currently only `volume` is used from there because replacing the `muted` state from `useVideoUtils()` causes the speaker to flicker on and off in some videos while the slider is moved, and I'm unsure as to why.
A simple slide animation to make the interaction not so sudden.

Easing copied from YouTube, since I really liked their little animation*.

*: Looking at Chromium DevTools, this specific function seems to be called "Fast Out, Linear In". So it seems to be a standard, at least from Google.
- Add tabIndex to slider
- Open slider immediately when the entire <AudioControls> component is focused
@IsaacMarovitz
Copy link

I think the bar should be a bit longer and perhaps slightly thinner here to avoid feeling finicky. Also, I can see in your examples that the end of the control is slightly clipped.

The slider defaults to 50% volume.

I think everyone would expect it to default to 100% not 50%

@mozzius
Copy link
Member

mozzius commented Sep 16, 2024

Thank you so much for this! I ended up redoing from scratch in #5363, but this PR was really helpful for doing the logarithmic volume controls. Much appreciated!

@mozzius mozzius closed this Sep 16, 2024
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

Successfully merging this pull request may close these issues.

Volume control for media player
3 participants