diff --git a/packages/vidstack/src/providers/vimeo/provider.ts b/packages/vidstack/src/providers/vimeo/provider.ts index c5cf29c66..7518087f7 100644 --- a/packages/vidstack/src/providers/vimeo/provider.ts +++ b/packages/vidstack/src/providers/vimeo/provider.ts @@ -291,8 +291,13 @@ export class VimeoProvider this._remote('getCurrentTime'); } + // Embed will sometimes dispatch 0 at end of playback. + private _skipTimeUpdates = false; + protected _onTimeUpdate(time: number, trigger: Event) { - const { realCurrentTime, paused, bufferedEnd } = this._ctx.$state; + if (this._skipTimeUpdates && time === 0) return; + + const { realCurrentTime, realDuration, paused, bufferedEnd } = this._ctx.$state; if (realCurrentTime() === time) return; @@ -312,6 +317,14 @@ export class VimeoProvider this._notify('waiting', undefined, trigger); } } + + if (realDuration() - time < 0.01) { + this._notify('end', undefined, trigger); + this._skipTimeUpdates = true; + setTimeout(() => { + this._skipTimeUpdates = false; + }, 500); + } } protected _getPlayedRange(time: number) { diff --git a/packages/vidstack/src/providers/youtube/provider.ts b/packages/vidstack/src/providers/youtube/provider.ts index 780cead80..6a4023e22 100644 --- a/packages/vidstack/src/providers/youtube/provider.ts +++ b/packages/vidstack/src/providers/youtube/provider.ts @@ -339,13 +339,13 @@ export class YouTubeProvider protected override _onMessage({ info }: YouTubeMessage, event: MessageEvent) { if (!info) return; - const { title, realDuration, playbackRate } = this._ctx.$state; + const { title, intrinsicDuration, playbackRate } = this._ctx.$state; if (isObject(info.videoData) && info.videoData.title !== title()) { this._notify('title-change', info.videoData.title, event); } - if (isNumber(info.duration) && info.duration !== realDuration()) { + if (isNumber(info.duration) && info.duration !== intrinsicDuration()) { if (isNumber(info.videoLoadedFraction)) { const buffered = info.progressState?.loaded ?? info.videoLoadedFraction * info.duration, seekable = new TimeRange(0, info.duration); @@ -369,7 +369,7 @@ export class YouTubeProvider } = info.progressState; this._onTimeUpdate(current, event); this._onProgress(loaded, new TimeRange(seekableStart, seekableEnd), event); - if (_duration !== duration()) { + if (_duration !== intrinsicDuration()) { this._notify('duration-change', _duration, event); } }