Skip to content

fix(youtube-player): YT.Player is not a constructor #20616

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 29, 2020
Merged
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
3 changes: 3 additions & 0 deletions src/youtube-player/youtube-player.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {createFakeYtNamespace} from './fake-youtube-player';
import {Subscription} from 'rxjs';

const VIDEO_ID = 'a12345';
const YT_LOADING_STATE_MOCK = {loading: 1, loaded: 0};

describe('YoutubePlayer', () => {
let playerCtorSpy: jasmine.Spy;
Expand Down Expand Up @@ -381,6 +382,8 @@ describe('YoutubePlayer', () => {
});

it('waits until the api is ready before initializing', () => {
(window.YT as any) = YT_LOADING_STATE_MOCK;

fixture = TestBed.createComponent(TestApp);
testComponent = fixture.debugElement.componentInstance;
fixture.detectChanges();
Expand Down
2 changes: 1 addition & 1 deletion src/youtube-player/youtube-player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export class YouTubePlayer implements AfterViewInit, OnDestroy, OnInit {
}

let iframeApiAvailableObs: Observable<boolean> = observableOf(true);
if (!window.YT) {
if (!window.YT || !window.YT.Player) {
if (this.showBeforeIframeApiLoads && (typeof ngDevMode === 'undefined' || ngDevMode)) {
throw new Error('Namespace YT not found, cannot construct embedded youtube player. ' +
'Please install the YouTube Player API Reference for iframe Embeds: ' +
Expand Down