@angular/youtube-player 17.0.0-next.7 → 17.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm2022/youtube-module.mjs +5 -5
- package/esm2022/youtube-player.mjs +110 -232
- package/fesm2022/youtube-player.mjs +113 -235
- package/fesm2022/youtube-player.mjs.map +1 -1
- package/index.d.ts +32 -27
- package/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
2
|
import { PLATFORM_ID, Component, ChangeDetectionStrategy, ViewEncapsulation, Inject, Input, Output, ViewChild, NgModule } from '@angular/core';
|
|
3
3
|
import { isPlatformBrowser } from '@angular/common';
|
|
4
|
-
import { Subject, BehaviorSubject,
|
|
5
|
-
import {
|
|
4
|
+
import { Subject, BehaviorSubject, fromEventPattern, of, Observable } from 'rxjs';
|
|
5
|
+
import { switchMap, takeUntil } from 'rxjs/operators';
|
|
6
6
|
|
|
7
7
|
/// <reference types="youtube" />
|
|
8
8
|
const DEFAULT_PLAYER_WIDTH = 640;
|
|
@@ -13,69 +13,28 @@ const DEFAULT_PLAYER_HEIGHT = 390;
|
|
|
13
13
|
* @see https://developers.google.com/youtube/iframe_api_reference
|
|
14
14
|
*/
|
|
15
15
|
class YouTubePlayer {
|
|
16
|
-
/** YouTube Video ID to view */
|
|
17
|
-
get videoId() {
|
|
18
|
-
return this._videoId.value;
|
|
19
|
-
}
|
|
20
|
-
set videoId(videoId) {
|
|
21
|
-
this._videoId.next(videoId);
|
|
22
|
-
}
|
|
23
16
|
/** Height of video player */
|
|
24
17
|
get height() {
|
|
25
|
-
return this._height
|
|
18
|
+
return this._height;
|
|
26
19
|
}
|
|
27
20
|
set height(height) {
|
|
28
|
-
this._height
|
|
21
|
+
this._height = height || DEFAULT_PLAYER_HEIGHT;
|
|
29
22
|
}
|
|
30
23
|
/** Width of video player */
|
|
31
24
|
get width() {
|
|
32
|
-
return this._width
|
|
25
|
+
return this._width;
|
|
33
26
|
}
|
|
34
27
|
set width(width) {
|
|
35
|
-
this._width
|
|
36
|
-
}
|
|
37
|
-
/** The moment when the player is supposed to start playing */
|
|
38
|
-
set startSeconds(startSeconds) {
|
|
39
|
-
this._startSeconds.next(startSeconds);
|
|
40
|
-
}
|
|
41
|
-
/** The moment when the player is supposed to stop playing */
|
|
42
|
-
set endSeconds(endSeconds) {
|
|
43
|
-
this._endSeconds.next(endSeconds);
|
|
44
|
-
}
|
|
45
|
-
/** The suggested quality of the player */
|
|
46
|
-
set suggestedQuality(suggestedQuality) {
|
|
47
|
-
this._suggestedQuality.next(suggestedQuality);
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Extra parameters used to configure the player. See:
|
|
51
|
-
* https://developers.google.com/youtube/player_parameters.html?playerVersion=HTML5#Parameters
|
|
52
|
-
*/
|
|
53
|
-
get playerVars() {
|
|
54
|
-
return this._playerVars.value;
|
|
55
|
-
}
|
|
56
|
-
set playerVars(playerVars) {
|
|
57
|
-
this._playerVars.next(playerVars);
|
|
58
|
-
}
|
|
59
|
-
/** Whether cookies inside the player have been disabled. */
|
|
60
|
-
get disableCookies() {
|
|
61
|
-
return this._disableCookies.value;
|
|
62
|
-
}
|
|
63
|
-
set disableCookies(value) {
|
|
64
|
-
this._disableCookies.next(!!value);
|
|
28
|
+
this._width = width || DEFAULT_PLAYER_WIDTH;
|
|
65
29
|
}
|
|
66
30
|
constructor(_ngZone, platformId) {
|
|
67
31
|
this._ngZone = _ngZone;
|
|
68
|
-
this._youtubeContainer = new Subject();
|
|
69
32
|
this._destroyed = new Subject();
|
|
70
33
|
this._playerChanges = new BehaviorSubject(undefined);
|
|
71
|
-
this.
|
|
72
|
-
this.
|
|
73
|
-
|
|
74
|
-
this.
|
|
75
|
-
this._endSeconds = new BehaviorSubject(undefined);
|
|
76
|
-
this._suggestedQuality = new BehaviorSubject(undefined);
|
|
77
|
-
this._playerVars = new BehaviorSubject(undefined);
|
|
78
|
-
this._disableCookies = new BehaviorSubject(false);
|
|
34
|
+
this._height = DEFAULT_PLAYER_HEIGHT;
|
|
35
|
+
this._width = DEFAULT_PLAYER_WIDTH;
|
|
36
|
+
/** Whether cookies inside the player have been disabled. */
|
|
37
|
+
this.disableCookies = false;
|
|
79
38
|
/** Outputs are direct proxies from the player itself. */
|
|
80
39
|
this.ready = this._getLazyEmitter('onReady');
|
|
81
40
|
this.stateChange = this._getLazyEmitter('onStateChange');
|
|
@@ -85,71 +44,50 @@ class YouTubePlayer {
|
|
|
85
44
|
this.playbackRateChange = this._getLazyEmitter('onPlaybackRateChange');
|
|
86
45
|
this._isBrowser = isPlatformBrowser(platformId);
|
|
87
46
|
}
|
|
88
|
-
|
|
47
|
+
ngAfterViewInit() {
|
|
89
48
|
// Don't do anything if we're not in a browser environment.
|
|
90
49
|
if (!this._isBrowser) {
|
|
91
50
|
return;
|
|
92
51
|
}
|
|
93
|
-
let iframeApiAvailableObs = of(true);
|
|
94
52
|
if (!window.YT || !window.YT.Player) {
|
|
95
53
|
if (this.showBeforeIframeApiLoads && (typeof ngDevMode === 'undefined' || ngDevMode)) {
|
|
96
54
|
throw new Error('Namespace YT not found, cannot construct embedded youtube player. ' +
|
|
97
55
|
'Please install the YouTube Player API Reference for iframe Embeds: ' +
|
|
98
56
|
'https://developers.google.com/youtube/iframe_api_reference');
|
|
99
57
|
}
|
|
100
|
-
const iframeApiAvailableSubject = new Subject();
|
|
101
58
|
this._existingApiReadyCallback = window.onYouTubeIframeAPIReady;
|
|
102
59
|
window.onYouTubeIframeAPIReady = () => {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
this._ngZone.run(() => iframeApiAvailableSubject.next(true));
|
|
60
|
+
this._existingApiReadyCallback?.();
|
|
61
|
+
this._ngZone.run(() => this._createPlayer());
|
|
107
62
|
};
|
|
108
|
-
iframeApiAvailableObs = iframeApiAvailableSubject.pipe(take(1), startWith(false));
|
|
109
63
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
64
|
+
else {
|
|
65
|
+
this._createPlayer();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
ngOnChanges(changes) {
|
|
69
|
+
if (this._shouldRecreatePlayer(changes)) {
|
|
70
|
+
this._createPlayer();
|
|
71
|
+
}
|
|
72
|
+
else if (this._player) {
|
|
73
|
+
if (changes['width'] || changes['height']) {
|
|
74
|
+
this._setSize();
|
|
120
75
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
playerObs.subscribe(player => {
|
|
124
|
-
this._player = player;
|
|
125
|
-
if (player && this._pendingPlayerState) {
|
|
126
|
-
this._initializePlayer(player, this._pendingPlayerState);
|
|
76
|
+
if (changes['suggestedQuality']) {
|
|
77
|
+
this._setQuality();
|
|
127
78
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
bindCueVideoCall(playerObs, this._videoId, this._startSeconds, this._endSeconds, this._suggestedQuality, this._destroyed);
|
|
133
|
-
// After all of the subscriptions are set up, connect the observable.
|
|
134
|
-
playerObs.connect();
|
|
135
|
-
}
|
|
136
|
-
ngAfterViewInit() {
|
|
137
|
-
this._youtubeContainer.next(this.youtubeContainer.nativeElement);
|
|
79
|
+
if (changes['startSeconds'] || changes['endSeconds'] || changes['suggestedQuality']) {
|
|
80
|
+
this._cuePlayer();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
138
83
|
}
|
|
139
84
|
ngOnDestroy() {
|
|
85
|
+
this._pendingPlayer?.destroy();
|
|
140
86
|
if (this._player) {
|
|
141
87
|
this._player.destroy();
|
|
142
88
|
window.onYouTubeIframeAPIReady = this._existingApiReadyCallback;
|
|
143
89
|
}
|
|
144
90
|
this._playerChanges.complete();
|
|
145
|
-
this._videoId.complete();
|
|
146
|
-
this._height.complete();
|
|
147
|
-
this._width.complete();
|
|
148
|
-
this._startSeconds.complete();
|
|
149
|
-
this._endSeconds.complete();
|
|
150
|
-
this._suggestedQuality.complete();
|
|
151
|
-
this._youtubeContainer.complete();
|
|
152
|
-
this._playerVars.complete();
|
|
153
91
|
this._destroyed.next();
|
|
154
92
|
this._destroyed.complete();
|
|
155
93
|
}
|
|
@@ -314,9 +252,57 @@ class YouTubePlayer {
|
|
|
314
252
|
}
|
|
315
253
|
return this._pendingPlayerState;
|
|
316
254
|
}
|
|
317
|
-
/**
|
|
318
|
-
|
|
319
|
-
|
|
255
|
+
/**
|
|
256
|
+
* Determines whether a change in the component state
|
|
257
|
+
* requires the YouTube player to be recreated.
|
|
258
|
+
*/
|
|
259
|
+
_shouldRecreatePlayer(changes) {
|
|
260
|
+
const change = changes['videoId'] || changes['playerVars'] || changes['disableCookies'];
|
|
261
|
+
return !!change && !change.isFirstChange();
|
|
262
|
+
}
|
|
263
|
+
/** Creates a new YouTube player and destroys the existing one. */
|
|
264
|
+
_createPlayer() {
|
|
265
|
+
this._player?.destroy();
|
|
266
|
+
this._pendingPlayer?.destroy();
|
|
267
|
+
// A player can't be created if the API isn't loaded,
|
|
268
|
+
// or there isn't a video or playlist to be played.
|
|
269
|
+
if (typeof YT === 'undefined' || (!this.videoId && !this.playerVars?.list)) {
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
// Important! We need to create the Player object outside of the `NgZone`, because it kicks
|
|
273
|
+
// off a 250ms setInterval which will continually trigger change detection if we don't.
|
|
274
|
+
const player = this._ngZone.runOutsideAngular(() => new YT.Player(this.youtubeContainer.nativeElement, {
|
|
275
|
+
videoId: this.videoId,
|
|
276
|
+
host: this.disableCookies ? 'https://www.youtube-nocookie.com' : undefined,
|
|
277
|
+
width: this.width,
|
|
278
|
+
height: this.height,
|
|
279
|
+
playerVars: this.playerVars,
|
|
280
|
+
}));
|
|
281
|
+
const whenReady = () => {
|
|
282
|
+
// Only assign the player once it's ready, otherwise YouTube doesn't expose some APIs.
|
|
283
|
+
this._player = player;
|
|
284
|
+
this._pendingPlayer = undefined;
|
|
285
|
+
player.removeEventListener('onReady', whenReady);
|
|
286
|
+
this._playerChanges.next(player);
|
|
287
|
+
this._setSize();
|
|
288
|
+
this._setQuality();
|
|
289
|
+
if (this._pendingPlayerState) {
|
|
290
|
+
this._applyPendingPlayerState(player, this._pendingPlayerState);
|
|
291
|
+
this._pendingPlayerState = undefined;
|
|
292
|
+
}
|
|
293
|
+
// Only cue the player when it either hasn't started yet or it's cued,
|
|
294
|
+
// otherwise cuing it can interrupt a player with autoplay enabled.
|
|
295
|
+
const state = player.getPlayerState();
|
|
296
|
+
if (state === YT.PlayerState.UNSTARTED || state === YT.PlayerState.CUED || state == null) {
|
|
297
|
+
this._cuePlayer();
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
this._pendingPlayer = player;
|
|
301
|
+
player.addEventListener('onReady', whenReady);
|
|
302
|
+
}
|
|
303
|
+
/** Applies any state that changed before the player was initialized. */
|
|
304
|
+
_applyPendingPlayerState(player, pendingState) {
|
|
305
|
+
const { playbackState, playbackRate, volume, muted, seek } = pendingState;
|
|
320
306
|
switch (playbackState) {
|
|
321
307
|
case YT.PlayerState.PLAYING:
|
|
322
308
|
player.playVideo();
|
|
@@ -341,6 +327,27 @@ class YouTubePlayer {
|
|
|
341
327
|
player.seekTo(seek.seconds, seek.allowSeekAhead);
|
|
342
328
|
}
|
|
343
329
|
}
|
|
330
|
+
/** Cues the player based on the current component state. */
|
|
331
|
+
_cuePlayer() {
|
|
332
|
+
if (this._player && this.videoId) {
|
|
333
|
+
this._player.cueVideoById({
|
|
334
|
+
videoId: this.videoId,
|
|
335
|
+
startSeconds: this.startSeconds,
|
|
336
|
+
endSeconds: this.endSeconds,
|
|
337
|
+
suggestedQuality: this.suggestedQuality,
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
/** Sets the player's size based on the current input values. */
|
|
342
|
+
_setSize() {
|
|
343
|
+
this._player?.setSize(this.width, this.height);
|
|
344
|
+
}
|
|
345
|
+
/** Sets the player's quality based on the current input values. */
|
|
346
|
+
_setQuality() {
|
|
347
|
+
if (this._player && this.suggestedQuality) {
|
|
348
|
+
this._player.setPlaybackQuality(this.suggestedQuality);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
344
351
|
/** Gets an observable that adds an event listener to the player when a user subscribes to it. */
|
|
345
352
|
_getLazyEmitter(name) {
|
|
346
353
|
// Start with the stream of players. This way the events will be transferred
|
|
@@ -357,9 +364,7 @@ class YouTubePlayer {
|
|
|
357
364
|
// expose whether the player has been destroyed so we have to wrap it in a try/catch to
|
|
358
365
|
// prevent the entire stream from erroring out.
|
|
359
366
|
try {
|
|
360
|
-
|
|
361
|
-
player.removeEventListener(name, listener);
|
|
362
|
-
}
|
|
367
|
+
player?.removeEventListener?.(name, listener);
|
|
363
368
|
}
|
|
364
369
|
catch { }
|
|
365
370
|
})
|
|
@@ -367,7 +372,7 @@ class YouTubePlayer {
|
|
|
367
372
|
}),
|
|
368
373
|
// By default we run all the API interactions outside the zone
|
|
369
374
|
// so we have to bring the events back in manually when they emit.
|
|
370
|
-
|
|
375
|
+
source => new Observable(observer => source.subscribe({
|
|
371
376
|
next: value => this._ngZone.run(() => observer.next(value)),
|
|
372
377
|
error: error => observer.error(error),
|
|
373
378
|
complete: () => observer.complete(),
|
|
@@ -375,10 +380,10 @@ class YouTubePlayer {
|
|
|
375
380
|
// Ensures that everything is cleared out on destroy.
|
|
376
381
|
takeUntil(this._destroyed));
|
|
377
382
|
}
|
|
378
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.0-
|
|
379
|
-
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.0.0-
|
|
383
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.0-rc.0", ngImport: i0, type: YouTubePlayer, deps: [{ token: i0.NgZone }, { token: PLATFORM_ID }], target: i0.ɵɵFactoryTarget.Component }); }
|
|
384
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.0.0-rc.0", type: YouTubePlayer, selector: "youtube-player", inputs: { videoId: "videoId", height: "height", width: "width", startSeconds: "startSeconds", endSeconds: "endSeconds", suggestedQuality: "suggestedQuality", playerVars: "playerVars", disableCookies: "disableCookies", showBeforeIframeApiLoads: "showBeforeIframeApiLoads" }, outputs: { ready: "ready", stateChange: "stateChange", error: "error", apiChange: "apiChange", playbackQualityChange: "playbackQualityChange", playbackRateChange: "playbackRateChange" }, viewQueries: [{ propertyName: "youtubeContainer", first: true, predicate: ["youtubeContainer"], descendants: true, static: true }], usesOnChanges: true, ngImport: i0, template: '<div #youtubeContainer></div>', isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
|
|
380
385
|
}
|
|
381
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.0-
|
|
386
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.0-rc.0", ngImport: i0, type: YouTubePlayer, decorators: [{
|
|
382
387
|
type: Component,
|
|
383
388
|
args: [{
|
|
384
389
|
selector: 'youtube-player',
|
|
@@ -422,143 +427,16 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.0-next.6",
|
|
|
422
427
|
type: Output
|
|
423
428
|
}], youtubeContainer: [{
|
|
424
429
|
type: ViewChild,
|
|
425
|
-
args: ['youtubeContainer']
|
|
430
|
+
args: ['youtubeContainer', { static: true }]
|
|
426
431
|
}] } });
|
|
427
|
-
/** Listens to changes to the given width and height and sets it on the player. */
|
|
428
|
-
function bindSizeToPlayer(playerObs, widthObs, heightObs) {
|
|
429
|
-
return combineLatest([playerObs, widthObs, heightObs]).subscribe(([player, width, height]) => player && player.setSize(width, height));
|
|
430
|
-
}
|
|
431
|
-
/** Listens to changes from the suggested quality and sets it on the given player. */
|
|
432
|
-
function bindSuggestedQualityToPlayer(playerObs, suggestedQualityObs) {
|
|
433
|
-
return combineLatest([playerObs, suggestedQualityObs]).subscribe(([player, suggestedQuality]) => player && suggestedQuality && player.setPlaybackQuality(suggestedQuality));
|
|
434
|
-
}
|
|
435
|
-
/**
|
|
436
|
-
* Returns an observable that emits the loaded player once it's ready. Certain properties/methods
|
|
437
|
-
* won't be available until the iframe finishes loading.
|
|
438
|
-
* @param onAbort Callback function that will be invoked if the player loading was aborted before
|
|
439
|
-
* it was able to complete. Can be used to clean up any loose references.
|
|
440
|
-
*/
|
|
441
|
-
function waitUntilReady(onAbort) {
|
|
442
|
-
return mergeMap(player => {
|
|
443
|
-
if (!player) {
|
|
444
|
-
return of(undefined);
|
|
445
|
-
}
|
|
446
|
-
if (playerIsReady(player)) {
|
|
447
|
-
return of(player);
|
|
448
|
-
}
|
|
449
|
-
// Since removeEventListener is not on Player when it's initialized, we can't use fromEvent.
|
|
450
|
-
// The player is not initialized fully until the ready is called.
|
|
451
|
-
return new Observable(emitter => {
|
|
452
|
-
let aborted = false;
|
|
453
|
-
let resolved = false;
|
|
454
|
-
const onReady = (event) => {
|
|
455
|
-
resolved = true;
|
|
456
|
-
if (!aborted) {
|
|
457
|
-
event.target.removeEventListener('onReady', onReady);
|
|
458
|
-
emitter.next(event.target);
|
|
459
|
-
}
|
|
460
|
-
};
|
|
461
|
-
player.addEventListener('onReady', onReady);
|
|
462
|
-
return () => {
|
|
463
|
-
aborted = true;
|
|
464
|
-
if (!resolved) {
|
|
465
|
-
onAbort(player);
|
|
466
|
-
}
|
|
467
|
-
};
|
|
468
|
-
}).pipe(take(1), startWith(undefined));
|
|
469
|
-
});
|
|
470
|
-
}
|
|
471
|
-
/** Create an observable for the player based on the given options. */
|
|
472
|
-
function createPlayerObservable(youtubeContainer, videoIdObs, hostObs, iframeApiAvailableObs, widthObs, heightObs, playerVarsObs, ngZone) {
|
|
473
|
-
const playerOptions = combineLatest([videoIdObs, hostObs, playerVarsObs]).pipe(withLatestFrom(combineLatest([widthObs, heightObs])), map(([constructorOptions, sizeOptions]) => {
|
|
474
|
-
const [videoId, host, playerVars] = constructorOptions;
|
|
475
|
-
const [width, height] = sizeOptions;
|
|
476
|
-
// If there's no video id or a list isn't supplied, bail out
|
|
477
|
-
if (!videoId && !(playerVars?.list && playerVars?.listType)) {
|
|
478
|
-
return undefined;
|
|
479
|
-
}
|
|
480
|
-
return { videoId, playerVars, width, height, host };
|
|
481
|
-
}));
|
|
482
|
-
return combineLatest([youtubeContainer, playerOptions, of(ngZone)]).pipe(skipUntilRememberLatest(iframeApiAvailableObs), scan(syncPlayerState, undefined), distinctUntilChanged());
|
|
483
|
-
}
|
|
484
|
-
/** Skips the given observable until the other observable emits true, then emit the latest. */
|
|
485
|
-
function skipUntilRememberLatest(notifier) {
|
|
486
|
-
return pipe(combineLatest$1(notifier), skipWhile(([_, doneSkipping]) => !doneSkipping), map(([value]) => value));
|
|
487
|
-
}
|
|
488
|
-
/** Destroy the player if there are no options, or create the player if there are options. */
|
|
489
|
-
function syncPlayerState(player, [container, videoOptions, ngZone]) {
|
|
490
|
-
if (player &&
|
|
491
|
-
videoOptions &&
|
|
492
|
-
(player.playerVars !== videoOptions.playerVars || player.host !== videoOptions.host)) {
|
|
493
|
-
// The player needs to be recreated if the playerVars are different.
|
|
494
|
-
player.destroy();
|
|
495
|
-
}
|
|
496
|
-
else if (!videoOptions) {
|
|
497
|
-
if (player) {
|
|
498
|
-
// Destroy the player if the videoId was removed.
|
|
499
|
-
player.destroy();
|
|
500
|
-
}
|
|
501
|
-
return;
|
|
502
|
-
}
|
|
503
|
-
else if (player) {
|
|
504
|
-
return player;
|
|
505
|
-
}
|
|
506
|
-
// Important! We need to create the Player object outside of the `NgZone`, because it kicks
|
|
507
|
-
// off a 250ms setInterval which will continually trigger change detection if we don't.
|
|
508
|
-
const newPlayer = ngZone.runOutsideAngular(() => new YT.Player(container, videoOptions));
|
|
509
|
-
newPlayer.videoId = videoOptions.videoId;
|
|
510
|
-
newPlayer.playerVars = videoOptions.playerVars;
|
|
511
|
-
newPlayer.host = videoOptions.host;
|
|
512
|
-
return newPlayer;
|
|
513
|
-
}
|
|
514
|
-
/**
|
|
515
|
-
* Call cueVideoById if the videoId changes, or when start or end seconds change. cueVideoById will
|
|
516
|
-
* change the loaded video id to the given videoId, and set the start and end times to the given
|
|
517
|
-
* start/end seconds.
|
|
518
|
-
*/
|
|
519
|
-
function bindCueVideoCall(playerObs, videoIdObs, startSecondsObs, endSecondsObs, suggestedQualityObs, destroyed) {
|
|
520
|
-
const cueOptionsObs = combineLatest([startSecondsObs, endSecondsObs]).pipe(map(([startSeconds, endSeconds]) => ({ startSeconds, endSeconds })));
|
|
521
|
-
// Only respond to changes in cue options if the player is not running.
|
|
522
|
-
const filteredCueOptions = cueOptionsObs.pipe(filterOnOther(playerObs, player => !!player && !hasPlayerStarted(player)));
|
|
523
|
-
// If the video id changed, there's no reason to run 'cue' unless the player
|
|
524
|
-
// was initialized with a different video id.
|
|
525
|
-
const changedVideoId = videoIdObs.pipe(filterOnOther(playerObs, (player, videoId) => !!player && player.videoId !== videoId));
|
|
526
|
-
// If the player changed, there's no reason to run 'cue' unless there are cue options.
|
|
527
|
-
const changedPlayer = playerObs.pipe(filterOnOther(combineLatest([videoIdObs, cueOptionsObs]), ([videoId, cueOptions], player) => !!player &&
|
|
528
|
-
(videoId != player.videoId || !!cueOptions.startSeconds || !!cueOptions.endSeconds)));
|
|
529
|
-
merge(changedPlayer, changedVideoId, filteredCueOptions)
|
|
530
|
-
.pipe(withLatestFrom(combineLatest([playerObs, videoIdObs, cueOptionsObs, suggestedQualityObs])), map(([_, values]) => values), takeUntil(destroyed))
|
|
531
|
-
.subscribe(([player, videoId, cueOptions, suggestedQuality]) => {
|
|
532
|
-
if (!videoId || !player) {
|
|
533
|
-
return;
|
|
534
|
-
}
|
|
535
|
-
player.videoId = videoId;
|
|
536
|
-
player.cueVideoById({
|
|
537
|
-
videoId,
|
|
538
|
-
suggestedQuality,
|
|
539
|
-
...cueOptions,
|
|
540
|
-
});
|
|
541
|
-
});
|
|
542
|
-
}
|
|
543
|
-
function hasPlayerStarted(player) {
|
|
544
|
-
const state = player.getPlayerState();
|
|
545
|
-
return state !== YT.PlayerState.UNSTARTED && state !== YT.PlayerState.CUED;
|
|
546
|
-
}
|
|
547
|
-
function playerIsReady(player) {
|
|
548
|
-
return 'getPlayerStatus' in player;
|
|
549
|
-
}
|
|
550
|
-
/** Combines the two observables temporarily for the filter function. */
|
|
551
|
-
function filterOnOther(otherObs, filterFn) {
|
|
552
|
-
return pipe(withLatestFrom(otherObs), filter(([value, other]) => filterFn(other, value)), map(([value]) => value));
|
|
553
|
-
}
|
|
554
432
|
|
|
555
433
|
const COMPONENTS = [YouTubePlayer];
|
|
556
434
|
class YouTubePlayerModule {
|
|
557
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.0-
|
|
558
|
-
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.0.0-
|
|
559
|
-
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.0.0-
|
|
435
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.0-rc.0", ngImport: i0, type: YouTubePlayerModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
436
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.0.0-rc.0", ngImport: i0, type: YouTubePlayerModule, declarations: [YouTubePlayer], exports: [YouTubePlayer] }); }
|
|
437
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.0.0-rc.0", ngImport: i0, type: YouTubePlayerModule }); }
|
|
560
438
|
}
|
|
561
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.0-
|
|
439
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.0-rc.0", ngImport: i0, type: YouTubePlayerModule, decorators: [{
|
|
562
440
|
type: NgModule,
|
|
563
441
|
args: [{
|
|
564
442
|
declarations: COMPONENTS,
|