Skip to content

Commit

Permalink
fix(player): vimeo not firing ended event
Browse files Browse the repository at this point in the history
closes #1103
  • Loading branch information
mihar-22 committed Jan 25, 2024
1 parent f4954d9 commit fba30c9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
15 changes: 14 additions & 1 deletion packages/vidstack/src/providers/vimeo/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions packages/vidstack/src/providers/youtube/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}
Expand Down

0 comments on commit fba30c9

Please sign in to comment.