-
Notifications
You must be signed in to change notification settings - Fork 131
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
<media-player> doesn't respect initial volume and muted props #1416
Comments
In further testing I've noticed that programmatically setting the volume is also a bit off if you do it right around the time you load the player. If I have a method that's called function onCanPlay() {
player.volume = 0.2;
player.muted = true;
player.play();
} It doesn't work. The player is unmuted at full volume when it loads. Same thing if I reverse the order: function onCanPlay() {
player.play();
player.volume = 0.2;
player.muted = true;
} Player is unmuted at full volume. A workaroundThe only workarounds I've found are to set a timeout for 0 ms that calls this code and then it works: function onCanPlay() {
player.play();
setTimeout(() => {
if (player) {
player.volume = 0.2;
player.muted = true; // works with a 0ms timeout
}
}, 0);
} This isn't a great solution; is there a preferred way to interact with volume programmatically? My use case is that I have a $store that holds volume and muting info for a number of different video and audio players and I need them to all sync up with the same volume variables, therefore if the program starts muted I need the player to also start muted. |
Tested and you can't use a setTimeout(() => {
remote.changeVolume(0.2);
remote.mute(true); // works
}, 0); This also only works if you setTimeout(). |
this bug is not present in v1.11.30-next i am using this in my nuxt app to only have 1 player unmuted |
The same is happening for |
Thanks for reporting! This is a hydration bug with Svelte 4 as mentioned in the docs. You can either upgrade to Svelte 5 or you can mount the player client-side only by dynamically importing it. |
Cool I’ll try this today, thanks! |
@mihar-22 as mentioned earlier, this bug is also affecting nuxt/vuejs. version v1.11.30-next is not affected. |
I just tested it and it works as expected, make sure you're setting volume between |
Here is a stackblitz reproducing the bug: https://stackblitz.com/edit/vidstack-examples-qufbsu?file=src%2FPlayer.vue The player's ref of volume is set to This bug is still present; can you please share how you have yours working? |
I can also reproduce this using the javascript/cdn import: https://stackblitz.com/edit/stackblitz-starters-jdj5p2?file=index.html |
same issue on nuxt. Everything works fine with 1.11.30. Thank you for the workaround. @mihar-22, really sorry for the ping, but i think is necessary to re-open the issue |
Current Behavior:
When embedding a
<media-player>
in Svelte withvolume
set to0
andmuted
set totrue
, the player starts at full volume.If you
bind:this={player}
and programatically setplayer.muted
andplayer.volume
it works.Expected Behavior:
The player should start muted.
Steps To Reproduce:
Reproduction Link: StackBlitz example
Environment:
Example:
Anything Else?
The text was updated successfully, but these errors were encountered: