Skip to content

Commit

Permalink
fix(player): youtube autoplay prevents interaction on fail
Browse files Browse the repository at this point in the history
closes #1316, #1325
  • Loading branch information
mihar-22 committed Jul 9, 2024
1 parent bc0b501 commit 6b3457d
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions packages/vidstack/src/providers/youtube/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ export class YouTubeProvider
return this._playPromise.promise;
}

private _playFail(message: string) {
this._playPromise?.reject(message);
this._playPromise = null;
}

async pause() {
const { paused } = this._ctx.$state;

Expand All @@ -129,6 +134,11 @@ export class YouTubeProvider
return this._pausePromise.promise;
}

private _pauseFail(message: string) {
this._pausePromise?.reject(message);
this._pausePromise = null;
}

setMuted(muted: boolean) {
if (muted) this._remote('mute');
else this._remote('unMute');
Expand Down Expand Up @@ -304,8 +314,7 @@ export class YouTubeProvider

// Embed incorrectly plays on initial seek operation.
if (!started() && isPlay && this._pausedSeeking) {
this._playPromise?.reject('invalid internal play operation');
this._playPromise = null;
this._playFail('invalid internal play operation');

if (isPlaying) {
this.pause();
Expand All @@ -323,6 +332,12 @@ export class YouTubeProvider
}

switch (state) {
case YouTubePlayerState._Unstarted:
// These methods will only reject if a play/pause is actually pending.
this._playFail('provider rejected');
this._pauseFail('provider rejected');
this._notify('pause', undefined, trigger);
break;
case YouTubePlayerState._Cued:
this._onReady(trigger);
break;
Expand Down

0 comments on commit 6b3457d

Please sign in to comment.