Repository navigation
fix(vimeo-video-element): keep paused in sync when pause() is called before load #268
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
Merged
spuppo-mux
merged 5 commits into
muxinc:main
from
spuppo-mux:fix/vimeo-pause-before-load
Nov 9, 2026
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4b2099b
fix(vimeo-video-element): update state synchronously before load comp…
spuppo-mux 9f5b59b
test: add test for this change and fixed broken tests.
spuppo-mux f435ae4
fix: don't call api.play if paused while waiting
spuppo-mux 2ae1bb6
test: switched the test to a playable video and added a play event count
spuppo-mux 4b9bdce
fix: reverted paused guard on play. Added regression test for that case
spuppo-mux File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -261,23 +261,6 @@ class VimeoVideoElement extends MediaPlayedRangesMixin(globalThis.HTMLElement ?? | |
| super.disconnectedCallback?.(); | ||
| } | ||
|
|
||
| #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(); | ||
| }; | ||
|
|
||
|
Comment on lines
-264
to
-280
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: this was just moved |
||
| #setupApiListeners() { | ||
| const textTracksVideo = document.createElement('video'); | ||
| this.textTracks = textTracksVideo.textTracks; | ||
|
|
@@ -310,24 +293,13 @@ class VimeoVideoElement extends MediaPlayedRangesMixin(globalThis.HTMLElement ?? | |
| // Make sure a `play` event is fired before the bufferstart event. | ||
| // For example Vimeo's `play` event is delayed decreasing video startup time. | ||
| this.api.on('bufferstart', () => { | ||
| if (this.#paused) { | ||
| this.#paused = false; | ||
| this.dispatchEvent(new Event('play')); | ||
| } | ||
| this.#onPlay(); | ||
| this.dispatchEvent(new Event('waiting')); | ||
| }); | ||
|
|
||
| this.api.on('play', () => { | ||
| if (!this.#paused) return; | ||
| this.#paused = false; | ||
| this.dispatchEvent(new Event('play')); | ||
| }); | ||
| this.api.on('play', () => this.#onPlay()); | ||
|
|
||
| this.api.on('playing', () => { | ||
| this.#readyState = 3; // HTMLMediaElement.HAVE_FUTURE_DATA | ||
| this.#paused = false; | ||
| this.dispatchEvent(new Event('playing')); | ||
| }); | ||
| this.api.on('playing', () => this.#onPlaying()); | ||
|
|
||
| this.api.on('seeking', () => { | ||
| this.#seeking = true; | ||
|
|
@@ -341,15 +313,9 @@ class VimeoVideoElement extends MediaPlayedRangesMixin(globalThis.HTMLElement ?? | |
| this.dispatchEvent(new Event('seeked')); | ||
| }); | ||
|
|
||
| this.api.on('pause', () => { | ||
| this.#paused = true; | ||
| this.dispatchEvent(new Event('pause')); | ||
| }); | ||
| this.api.on('pause', () => this.#onPaused()); | ||
|
|
||
| this.api.on('ended', () => { | ||
| this.#paused = true; | ||
| this.dispatchEvent(new Event('ended')); | ||
| }); | ||
| this.api.on('ended', () => this.#onEnded()); | ||
|
|
||
| this.api.on('ratechange', ({ playbackRate }) => { | ||
| this.#playbackRate = playbackRate; | ||
|
|
@@ -412,22 +378,27 @@ class VimeoVideoElement extends MediaPlayedRangesMixin(globalThis.HTMLElement ?? | |
| } | ||
| } | ||
|
|
||
| /* | ||
| * Update state synchronously. If this is called before | ||
| * load completes, Vimeo never starts playback and won't emit the respective event. | ||
| */ | ||
| async play() { | ||
| this.#paused = false; | ||
| this.dispatchEvent(new Event('play')); | ||
| this.#onPlay(); | ||
|
|
||
| await this.loadComplete; | ||
|
|
||
| try { | ||
| await this.api?.play(); | ||
| } catch (error) { | ||
| this.#paused = true; | ||
| this.dispatchEvent(new Event('pause')); | ||
| this.#onPaused(); | ||
|
cursor[bot] marked this conversation as resolved.
Resolved
|
||
| throw error; | ||
| } | ||
| } | ||
|
|
||
| async pause() { | ||
| // Update state synchronously. See play(). | ||
| this.#onPaused(); | ||
|
|
||
| await this.loadComplete; | ||
| return this.api?.pause(); | ||
| } | ||
|
|
@@ -582,6 +553,46 @@ class VimeoVideoElement extends MediaPlayedRangesMixin(globalThis.HTMLElement ?? | |
| }); | ||
| } | ||
|
|
||
| #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(); | ||
| }; | ||
|
|
||
| #onPlay() { | ||
| if (!this.#paused) return; | ||
| this.#paused = false; | ||
| this.dispatchEvent(new Event('play')); | ||
| } | ||
|
|
||
| #onPlaying() { | ||
| this.#readyState = 3; // HTMLMediaElement.HAVE_FUTURE_DATA | ||
| this.#paused = false; | ||
| this.dispatchEvent(new Event('playing')); | ||
| } | ||
|
|
||
| #onPaused() { | ||
| if (this.#paused) return; | ||
| this.#paused = true; | ||
| this.dispatchEvent(new Event('pause')); | ||
| } | ||
|
|
||
| #onEnded() { | ||
| this.#paused = true; | ||
| this.dispatchEvent(new Event('ended')); | ||
| } | ||
|
|
||
| // This is a pattern to update property values that are set before | ||
| // the custom element is upgraded. | ||
| // https://web.dev/custom-elements-best-practices/#make-properties-lazy | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.