Skip to content

Media API rough edges #2879

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

Closed
prsdta opened this issue May 27, 2019 · 4 comments
Closed

Media API rough edges #2879

prsdta opened this issue May 27, 2019 · 4 comments

Comments

@prsdta
Copy link

prsdta commented May 27, 2019

Hi, trying to play around Svelte, I'm having an issue with the media elements bindings, specifically buffered.

REPL repro: https://svelte.dev/repl/021f1c1d512e49248347bfe746f037ad?version=3.4.3

Basically my issue is that I'm trying to setup a reactive variable that depends on the buffered property, but that fails on load, because buffered is not yet instantiated? (maybe?)

Like this (variables initialized outside the block):

  $: {
    progressBarPercent = (currentTime / duration) * 100;
    loadedPercent = buffered.end(buffered.length - 1) / duration;
  }

On my machine I'm getting a: proxy.js:135 TypeError: Cannot read property 'end' of undefined with this kind of output:

$$self.$$.update = ($$dirty = { currentTime: 1, duration: 1, buffered: 1 }) => {
  if ($$dirty.currentTime || $$dirty.duration || $$dirty.buffered) { {
  $$invalidate('progressBarPercent', progressBarPercent = (currentTime / duration) * 100);
  $$invalidate('loadedPercent', loadedPercent = buffered.end / duration);
  } }
};

I've been able to find a workaround that is simply wrapping the loadedPercent assignment in an if block and then, the updating behavior seems correct.

Looking in the repo I've found this #832 but this TimeRanges modification doesn't seem to happen in the current version, and if I were, an update to the docs would probably be nice.

Am I doing something wrong or it is a bug?

@timeshift92
Copy link

@stale
Copy link

stale bot commented Jun 26, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale
Copy link

stale bot commented Dec 27, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale-bot label Dec 27, 2021
@Rich-Harris
Copy link
Member

The REPL appears to work in Svelte 5, but in general bound values should be treated as potentially undefined in a $: ... statement. In idiomatic Svelte 5 code, this would use $effect which won't run until after bindings have settled.

@Rich-Harris Rich-Harris closed this as not planned Won't fix, can't repro, duplicate, stale Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants