Open Layendan opened 1 year ago
The volume
binding is provided by the volumechange
event.
If the user does not interact with the volume controls, this event will never fire.
Maybe code could be generated that reads the value once, if the bound variable is undefined
.
As a workaround, just initialize the variable yourself.
The .volume
prop is set on the DOM element right away though, I'm not sure why we're not running the code once upon creation that would grab that volume even before the event has fired once, like we're doing for the other types of bindings.
Can confirm that initializing it fixes the problem. However, I feel like that's counter-intuitive as all other bindings do not need initialization.
Maybe we could just do one of these:
1
in case volume is undefined@Conduitry Can you give an example for where that happens?
I assumed that it might happen on input
elements, but to my surprise that does not seem to be the case.
<script>
let value;
let checked;
</script>
<input type=text bind:value />
<input type=checkbox bind:checked />
<p>{value}</p>
<p>{checked}</p>
Both value
and checked
are undefined
until user interaction.
@Layendan
It should not be initialized to 1
but simply the value of the DOM property as @Conduitry suggested.
You cannot assume 1 because user agents may use different defaults.
You can easily read the value yourself with an action, by the way:
<script>
let volume;
const action = (node, callback) => callback(node);
</script>
<!-- svelte-ignore a11y-media-has-caption -->
<video src="https://sveltejs.github.io/assets/caminandes-llamigos.mp4"
use:action={v => volume = v.volume}
bind:volume
controls />
<div>Volume: {volume}</div>
@Conduitry I would like to work on this issue, there is few things here I noticed.
like we're doing for the other types of bindings.
what do you mean here? the initial value of the state inside the instance is same as the value provided.
Replying very late :( , but I would like to pick to this up @Rich-Harris
Btw this is not reproducible in the latest version of svelte.
Describe the bug
When using
bind:volume
on video (did not test on audio track), it returns undefined instead of a number from 0-1.Reproduction
REPL for reproduction based on media element bindings tutorial REPL: https://svelte.dev/repl/d4acb0c4bf3e42efbc41d289f33ee359?version=3.52.0 ^ Click on video and check console, you can keep clicking to see that it only returns undefined. Tutorial: https://svelte.dev/tutorial/media-elements
Logs
No response
System Info
Severity
annoyance