Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/youtube-player/youtube-player.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,22 @@ describe('YoutubePlayer', () => {
expect(playerCtorSpy).toHaveBeenCalled();
});

it('should apply startSeconds when disablePlaceholder and autoplay are both set', () => {
testComponent.disablePlaceholder = true;
testComponent.playerVars = {autoplay: 1};
testComponent.startSeconds = 30;
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();

// Simulate player state being PLAYING (autoplay has started the video)
playerSpy.getPlayerState.and.returnValue(window.YT!.PlayerState.PLAYING);
events.onReady({target: playerSpy});

// Should use seekTo instead of cueVideoById when player is already playing
expect(playerSpy.seekTo).toHaveBeenCalledWith(30, true);
expect(playerSpy.cueVideoById).not.toHaveBeenCalled();
});

it('should allow for the placeholder image quality to be changed', () => {
const placeholder = getPlaceholder(fixture);
expect(placeholder.style.backgroundImage).toContain(
Expand Down
14 changes: 9 additions & 5 deletions src/youtube-player/youtube-player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -628,11 +628,15 @@ 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.
} else if (
(playVideo || this.playerVars?.autoplay === 1) &&
this.startSeconds &&
this.startSeconds > 0
) {
// We have to use `seekTo` when `startSeconds` are specified with a playing video
// (either from user interaction or autoplay). 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);
}

Expand Down