Skip to content

Commit

Permalink
fix(youtube-player): startSeconds not applied when using placeholder
Browse files Browse the repository at this point in the history
Fixes that the `startSeconds` input wasn't doing anything if there's a placeholder. This used to work, but seems to have broken during the transition to using the placeholder.

Fixes #29874.

(cherry picked from commit 23ecba2)
  • Loading branch information
crisbeto committed Nov 11, 2024
1 parent b7f509c commit 2885987
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/dev-app/youtube-player/youtube-player-demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ <h2>Basic Example</h2>
<div class="demo-video-selection">
<mat-checkbox [(ngModel)]="disableCookies">Disable cookies</mat-checkbox>
<mat-checkbox [(ngModel)]="disablePlaceholder">Disable placeholder</mat-checkbox>
<mat-checkbox [(ngModel)]="startAt30s">Start at 30s</mat-checkbox>
</div>
<youtube-player [videoId]="selectedVideoId"
[playerVars]="playerVars"
[startSeconds]="startAt30s ? 30 : 0"
[width]="videoWidth"
[height]="videoHeight"
[disableCookies]="disableCookies"
Expand Down
1 change: 1 addition & 0 deletions src/dev-app/youtube-player/youtube-player-demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export class YouTubePlayerDemo implements AfterViewInit, OnDestroy {
videoHeight: number | undefined;
disableCookies = false;
disablePlaceholder = false;
startAt30s = false;
placeholderQuality: PlaceholderImageQuality;

constructor() {
Expand Down
6 changes: 6 additions & 0 deletions src/youtube-player/youtube-player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,12 @@ export class YouTubePlayer implements AfterViewInit, OnChanges, OnDestroy {
const state = player.getPlayerState();
if (state === PlayerState.UNSTARTED || state === PlayerState.CUED || state == null) {
this._cuePlayer();
} else if (playVideo && this.startSeconds && this.startSeconds > 0) {
// We have to use `seekTo` when `startSeconds` are specified to simulate it playing from
// a specific time. The "proper" way to do it would be to either go through `cueVideoById`
// or `playerVars.start`, but at the time of writing both end up resetting the video
// to the state as if the user hasn't interacted with it.
player.seekTo(this.startSeconds, true);
}

this._changeDetectorRef.markForCheck();
Expand Down

0 comments on commit 2885987

Please sign in to comment.