Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
fix: loaded handling
Browse files Browse the repository at this point in the history
  • Loading branch information
luwes committed Jul 19, 2022
1 parent 75fc122 commit c3ef96e
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions src/vimeo-video-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,30 @@ class VimeoVideoElement extends HTMLElement {
transparent: false,
};

const onLoaded = async () => {
this.#readyState = 1; // HTMLMediaElement.HAVE_METADATA
this.dispatchEvent(new Event('loadedmetadata'));

if (this.api) {
this.#muted = await this.api.getMuted();
this.#volume = await this.api.getVolume();
this.dispatchEvent(new Event('volumechange'));

this.#duration = await this.api.getDuration();
this.dispatchEvent(new Event('durationchange'));
}

this.dispatchEvent(new Event('loadcomplete'));
this.loadComplete.resolve();
};

if (this.noInit) {
this.api = oldApi;
this.api.loadVideo({
await this.api.loadVideo({
...this.#options,
url: this.src,
});
await onLoaded();
await this.loadComplete;
return;
}
Expand All @@ -127,23 +145,11 @@ class VimeoVideoElement extends HTMLElement {
}

this.api = new VimeoPlayerAPI(iframe);

this.api.on('loaded', async () => {
this.#readyState = 1; // HTMLMediaElement.HAVE_METADATA
this.dispatchEvent(new Event('loadedmetadata'));

if (this.api) {
this.#muted = await this.api.getMuted();
this.#volume = await this.api.getVolume();
this.dispatchEvent(new Event('volumechange'));

this.#duration = await this.api.getDuration();
this.dispatchEvent(new Event('durationchange'));
}

this.dispatchEvent(new Event('loadcomplete'));
this.loadComplete.resolve();
});
const onceLoaded = () => {
this.api.off('loaded', onceLoaded);
onLoaded();
}
this.api.on('loaded', onceLoaded);

// Make sure a `play` event is fired before the bufferstart event.
// For example Vimeo's `play` event is delayed decreasing video startup time.
Expand Down

1 comment on commit c3ef96e

@vercel
Copy link

@vercel vercel bot commented on c3ef96e Jul 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

vimeo-video-element – ./

vimeo-video-element-luwes.vercel.app
vimeo-video-element-git-main-luwes.vercel.app
vimeo-video-element.vercel.app

Please sign in to comment.