@angular/youtube-player 13.0.0-next.7 → 13.0.0-rc.2

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.
@@ -1,931 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('rxjs'), require('rxjs/operators')) :
3
- typeof define === 'function' && define.amd ? define('@angular/youtube-player', ['exports', '@angular/core', '@angular/common', 'rxjs', 'rxjs/operators'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.ng = global.ng || {}, global.ng.youtubePlayer = {}), global.ng.core, global.ng.common, global.rxjs, global.rxjs.operators));
5
- }(this, (function (exports, core, common, rxjs, operators) { 'use strict';
6
-
7
- /*! *****************************************************************************
8
- Copyright (c) Microsoft Corporation.
9
-
10
- Permission to use, copy, modify, and/or distribute this software for any
11
- purpose with or without fee is hereby granted.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
14
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
16
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
18
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19
- PERFORMANCE OF THIS SOFTWARE.
20
- ***************************************************************************** */
21
- /* global Reflect, Promise */
22
- var extendStatics = function (d, b) {
23
- extendStatics = Object.setPrototypeOf ||
24
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
25
- function (d, b) { for (var p in b)
26
- if (Object.prototype.hasOwnProperty.call(b, p))
27
- d[p] = b[p]; };
28
- return extendStatics(d, b);
29
- };
30
- function __extends(d, b) {
31
- if (typeof b !== "function" && b !== null)
32
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
33
- extendStatics(d, b);
34
- function __() { this.constructor = d; }
35
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
36
- }
37
- var __assign = function () {
38
- __assign = Object.assign || function __assign(t) {
39
- for (var s, i = 1, n = arguments.length; i < n; i++) {
40
- s = arguments[i];
41
- for (var p in s)
42
- if (Object.prototype.hasOwnProperty.call(s, p))
43
- t[p] = s[p];
44
- }
45
- return t;
46
- };
47
- return __assign.apply(this, arguments);
48
- };
49
- function __rest(s, e) {
50
- var t = {};
51
- for (var p in s)
52
- if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
53
- t[p] = s[p];
54
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
55
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
56
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
57
- t[p[i]] = s[p[i]];
58
- }
59
- return t;
60
- }
61
- function __decorate(decorators, target, key, desc) {
62
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
63
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
64
- r = Reflect.decorate(decorators, target, key, desc);
65
- else
66
- for (var i = decorators.length - 1; i >= 0; i--)
67
- if (d = decorators[i])
68
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
69
- return c > 3 && r && Object.defineProperty(target, key, r), r;
70
- }
71
- function __param(paramIndex, decorator) {
72
- return function (target, key) { decorator(target, key, paramIndex); };
73
- }
74
- function __metadata(metadataKey, metadataValue) {
75
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
76
- return Reflect.metadata(metadataKey, metadataValue);
77
- }
78
- function __awaiter(thisArg, _arguments, P, generator) {
79
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
80
- return new (P || (P = Promise))(function (resolve, reject) {
81
- function fulfilled(value) { try {
82
- step(generator.next(value));
83
- }
84
- catch (e) {
85
- reject(e);
86
- } }
87
- function rejected(value) { try {
88
- step(generator["throw"](value));
89
- }
90
- catch (e) {
91
- reject(e);
92
- } }
93
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
94
- step((generator = generator.apply(thisArg, _arguments || [])).next());
95
- });
96
- }
97
- function __generator(thisArg, body) {
98
- var _ = { label: 0, sent: function () { if (t[0] & 1)
99
- throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
100
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
101
- function verb(n) { return function (v) { return step([n, v]); }; }
102
- function step(op) {
103
- if (f)
104
- throw new TypeError("Generator is already executing.");
105
- while (_)
106
- try {
107
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
108
- return t;
109
- if (y = 0, t)
110
- op = [op[0] & 2, t.value];
111
- switch (op[0]) {
112
- case 0:
113
- case 1:
114
- t = op;
115
- break;
116
- case 4:
117
- _.label++;
118
- return { value: op[1], done: false };
119
- case 5:
120
- _.label++;
121
- y = op[1];
122
- op = [0];
123
- continue;
124
- case 7:
125
- op = _.ops.pop();
126
- _.trys.pop();
127
- continue;
128
- default:
129
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
130
- _ = 0;
131
- continue;
132
- }
133
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
134
- _.label = op[1];
135
- break;
136
- }
137
- if (op[0] === 6 && _.label < t[1]) {
138
- _.label = t[1];
139
- t = op;
140
- break;
141
- }
142
- if (t && _.label < t[2]) {
143
- _.label = t[2];
144
- _.ops.push(op);
145
- break;
146
- }
147
- if (t[2])
148
- _.ops.pop();
149
- _.trys.pop();
150
- continue;
151
- }
152
- op = body.call(thisArg, _);
153
- }
154
- catch (e) {
155
- op = [6, e];
156
- y = 0;
157
- }
158
- finally {
159
- f = t = 0;
160
- }
161
- if (op[0] & 5)
162
- throw op[1];
163
- return { value: op[0] ? op[1] : void 0, done: true };
164
- }
165
- }
166
- var __createBinding = Object.create ? (function (o, m, k, k2) {
167
- if (k2 === undefined)
168
- k2 = k;
169
- Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
170
- }) : (function (o, m, k, k2) {
171
- if (k2 === undefined)
172
- k2 = k;
173
- o[k2] = m[k];
174
- });
175
- function __exportStar(m, o) {
176
- for (var p in m)
177
- if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
178
- __createBinding(o, m, p);
179
- }
180
- function __values(o) {
181
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
182
- if (m)
183
- return m.call(o);
184
- if (o && typeof o.length === "number")
185
- return {
186
- next: function () {
187
- if (o && i >= o.length)
188
- o = void 0;
189
- return { value: o && o[i++], done: !o };
190
- }
191
- };
192
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
193
- }
194
- function __read(o, n) {
195
- var m = typeof Symbol === "function" && o[Symbol.iterator];
196
- if (!m)
197
- return o;
198
- var i = m.call(o), r, ar = [], e;
199
- try {
200
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
201
- ar.push(r.value);
202
- }
203
- catch (error) {
204
- e = { error: error };
205
- }
206
- finally {
207
- try {
208
- if (r && !r.done && (m = i["return"]))
209
- m.call(i);
210
- }
211
- finally {
212
- if (e)
213
- throw e.error;
214
- }
215
- }
216
- return ar;
217
- }
218
- /** @deprecated */
219
- function __spread() {
220
- for (var ar = [], i = 0; i < arguments.length; i++)
221
- ar = ar.concat(__read(arguments[i]));
222
- return ar;
223
- }
224
- /** @deprecated */
225
- function __spreadArrays() {
226
- for (var s = 0, i = 0, il = arguments.length; i < il; i++)
227
- s += arguments[i].length;
228
- for (var r = Array(s), k = 0, i = 0; i < il; i++)
229
- for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
230
- r[k] = a[j];
231
- return r;
232
- }
233
- function __spreadArray(to, from, pack) {
234
- if (pack || arguments.length === 2)
235
- for (var i = 0, l = from.length, ar; i < l; i++) {
236
- if (ar || !(i in from)) {
237
- if (!ar)
238
- ar = Array.prototype.slice.call(from, 0, i);
239
- ar[i] = from[i];
240
- }
241
- }
242
- return to.concat(ar || Array.prototype.slice.call(from));
243
- }
244
- function __await(v) {
245
- return this instanceof __await ? (this.v = v, this) : new __await(v);
246
- }
247
- function __asyncGenerator(thisArg, _arguments, generator) {
248
- if (!Symbol.asyncIterator)
249
- throw new TypeError("Symbol.asyncIterator is not defined.");
250
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
251
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
252
- function verb(n) { if (g[n])
253
- i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
254
- function resume(n, v) { try {
255
- step(g[n](v));
256
- }
257
- catch (e) {
258
- settle(q[0][3], e);
259
- } }
260
- function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
261
- function fulfill(value) { resume("next", value); }
262
- function reject(value) { resume("throw", value); }
263
- function settle(f, v) { if (f(v), q.shift(), q.length)
264
- resume(q[0][0], q[0][1]); }
265
- }
266
- function __asyncDelegator(o) {
267
- var i, p;
268
- return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
269
- function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
270
- }
271
- function __asyncValues(o) {
272
- if (!Symbol.asyncIterator)
273
- throw new TypeError("Symbol.asyncIterator is not defined.");
274
- var m = o[Symbol.asyncIterator], i;
275
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
276
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
277
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
278
- }
279
- function __makeTemplateObject(cooked, raw) {
280
- if (Object.defineProperty) {
281
- Object.defineProperty(cooked, "raw", { value: raw });
282
- }
283
- else {
284
- cooked.raw = raw;
285
- }
286
- return cooked;
287
- }
288
- ;
289
- var __setModuleDefault = Object.create ? (function (o, v) {
290
- Object.defineProperty(o, "default", { enumerable: true, value: v });
291
- }) : function (o, v) {
292
- o["default"] = v;
293
- };
294
- function __importStar(mod) {
295
- if (mod && mod.__esModule)
296
- return mod;
297
- var result = {};
298
- if (mod != null)
299
- for (var k in mod)
300
- if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
301
- __createBinding(result, mod, k);
302
- __setModuleDefault(result, mod);
303
- return result;
304
- }
305
- function __importDefault(mod) {
306
- return (mod && mod.__esModule) ? mod : { default: mod };
307
- }
308
- function __classPrivateFieldGet(receiver, state, kind, f) {
309
- if (kind === "a" && !f)
310
- throw new TypeError("Private accessor was defined without a getter");
311
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
312
- throw new TypeError("Cannot read private member from an object whose class did not declare it");
313
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
314
- }
315
- function __classPrivateFieldSet(receiver, state, value, kind, f) {
316
- if (kind === "m")
317
- throw new TypeError("Private method is not writable");
318
- if (kind === "a" && !f)
319
- throw new TypeError("Private accessor was defined without a setter");
320
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
321
- throw new TypeError("Cannot write private member to an object whose class did not declare it");
322
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
323
- }
324
-
325
- var DEFAULT_PLAYER_WIDTH = 640;
326
- var DEFAULT_PLAYER_HEIGHT = 390;
327
- /**
328
- * Angular component that renders a YouTube player via the YouTube player
329
- * iframe API.
330
- * @see https://developers.google.com/youtube/iframe_api_reference
331
- */
332
- var YouTubePlayer = /** @class */ (function () {
333
- function YouTubePlayer(_ngZone, platformId) {
334
- this._ngZone = _ngZone;
335
- this._youtubeContainer = new rxjs.Subject();
336
- this._destroyed = new rxjs.Subject();
337
- this._playerChanges = new rxjs.BehaviorSubject(undefined);
338
- this._videoId = new rxjs.BehaviorSubject(undefined);
339
- this._height = new rxjs.BehaviorSubject(DEFAULT_PLAYER_HEIGHT);
340
- this._width = new rxjs.BehaviorSubject(DEFAULT_PLAYER_WIDTH);
341
- this._startSeconds = new rxjs.BehaviorSubject(undefined);
342
- this._endSeconds = new rxjs.BehaviorSubject(undefined);
343
- this._suggestedQuality = new rxjs.BehaviorSubject(undefined);
344
- this._playerVars = new rxjs.BehaviorSubject(undefined);
345
- /** Outputs are direct proxies from the player itself. */
346
- this.ready = this._getLazyEmitter('onReady');
347
- this.stateChange = this._getLazyEmitter('onStateChange');
348
- this.error = this._getLazyEmitter('onError');
349
- this.apiChange = this._getLazyEmitter('onApiChange');
350
- this.playbackQualityChange = this._getLazyEmitter('onPlaybackQualityChange');
351
- this.playbackRateChange = this._getLazyEmitter('onPlaybackRateChange');
352
- this._isBrowser = common.isPlatformBrowser(platformId);
353
- }
354
- Object.defineProperty(YouTubePlayer.prototype, "videoId", {
355
- /** YouTube Video ID to view */
356
- get: function () { return this._videoId.value; },
357
- set: function (videoId) {
358
- this._videoId.next(videoId);
359
- },
360
- enumerable: false,
361
- configurable: true
362
- });
363
- Object.defineProperty(YouTubePlayer.prototype, "height", {
364
- /** Height of video player */
365
- get: function () { return this._height.value; },
366
- set: function (height) {
367
- this._height.next(height || DEFAULT_PLAYER_HEIGHT);
368
- },
369
- enumerable: false,
370
- configurable: true
371
- });
372
- Object.defineProperty(YouTubePlayer.prototype, "width", {
373
- /** Width of video player */
374
- get: function () { return this._width.value; },
375
- set: function (width) {
376
- this._width.next(width || DEFAULT_PLAYER_WIDTH);
377
- },
378
- enumerable: false,
379
- configurable: true
380
- });
381
- Object.defineProperty(YouTubePlayer.prototype, "startSeconds", {
382
- /** The moment when the player is supposed to start playing */
383
- set: function (startSeconds) {
384
- this._startSeconds.next(startSeconds);
385
- },
386
- enumerable: false,
387
- configurable: true
388
- });
389
- Object.defineProperty(YouTubePlayer.prototype, "endSeconds", {
390
- /** The moment when the player is supposed to stop playing */
391
- set: function (endSeconds) {
392
- this._endSeconds.next(endSeconds);
393
- },
394
- enumerable: false,
395
- configurable: true
396
- });
397
- Object.defineProperty(YouTubePlayer.prototype, "suggestedQuality", {
398
- /** The suggested quality of the player */
399
- set: function (suggestedQuality) {
400
- this._suggestedQuality.next(suggestedQuality);
401
- },
402
- enumerable: false,
403
- configurable: true
404
- });
405
- Object.defineProperty(YouTubePlayer.prototype, "playerVars", {
406
- /**
407
- * Extra parameters used to configure the player. See:
408
- * https://developers.google.com/youtube/player_parameters.html?playerVersion=HTML5#Parameters
409
- */
410
- get: function () { return this._playerVars.value; },
411
- set: function (playerVars) {
412
- this._playerVars.next(playerVars);
413
- },
414
- enumerable: false,
415
- configurable: true
416
- });
417
- YouTubePlayer.prototype.ngOnInit = function () {
418
- var _this = this;
419
- // Don't do anything if we're not in a browser environment.
420
- if (!this._isBrowser) {
421
- return;
422
- }
423
- var iframeApiAvailableObs = rxjs.of(true);
424
- if (!window.YT || !window.YT.Player) {
425
- if (this.showBeforeIframeApiLoads && (typeof ngDevMode === 'undefined' || ngDevMode)) {
426
- throw new Error('Namespace YT not found, cannot construct embedded youtube player. ' +
427
- 'Please install the YouTube Player API Reference for iframe Embeds: ' +
428
- 'https://developers.google.com/youtube/iframe_api_reference');
429
- }
430
- var iframeApiAvailableSubject_1 = new rxjs.Subject();
431
- this._existingApiReadyCallback = window.onYouTubeIframeAPIReady;
432
- window.onYouTubeIframeAPIReady = function () {
433
- if (_this._existingApiReadyCallback) {
434
- _this._existingApiReadyCallback();
435
- }
436
- _this._ngZone.run(function () { return iframeApiAvailableSubject_1.next(true); });
437
- };
438
- iframeApiAvailableObs = iframeApiAvailableSubject_1.pipe(operators.take(1), operators.startWith(false));
439
- }
440
- // An observable of the currently loaded player.
441
- var playerObs = createPlayerObservable(this._youtubeContainer, this._videoId, iframeApiAvailableObs, this._width, this._height, this._playerVars, this._ngZone).pipe(operators.tap(function (player) {
442
- // Emit this before the `waitUntilReady` call so that we can bind to
443
- // events that happen as the player is being initialized (e.g. `onReady`).
444
- _this._playerChanges.next(player);
445
- }), waitUntilReady(function (player) {
446
- // Destroy the player if loading was aborted so that we don't end up leaking memory.
447
- if (!playerIsReady(player)) {
448
- player.destroy();
449
- }
450
- }), operators.takeUntil(this._destroyed), operators.publish());
451
- // Set up side effects to bind inputs to the player.
452
- playerObs.subscribe(function (player) {
453
- _this._player = player;
454
- if (player && _this._pendingPlayerState) {
455
- _this._initializePlayer(player, _this._pendingPlayerState);
456
- }
457
- _this._pendingPlayerState = undefined;
458
- });
459
- bindSizeToPlayer(playerObs, this._width, this._height);
460
- bindSuggestedQualityToPlayer(playerObs, this._suggestedQuality);
461
- bindCueVideoCall(playerObs, this._videoId, this._startSeconds, this._endSeconds, this._suggestedQuality, this._destroyed);
462
- // After all of the subscriptions are set up, connect the observable.
463
- playerObs.connect();
464
- };
465
- YouTubePlayer.prototype.ngAfterViewInit = function () {
466
- this._youtubeContainer.next(this.youtubeContainer.nativeElement);
467
- };
468
- YouTubePlayer.prototype.ngOnDestroy = function () {
469
- if (this._player) {
470
- this._player.destroy();
471
- window.onYouTubeIframeAPIReady = this._existingApiReadyCallback;
472
- }
473
- this._playerChanges.complete();
474
- this._videoId.complete();
475
- this._height.complete();
476
- this._width.complete();
477
- this._startSeconds.complete();
478
- this._endSeconds.complete();
479
- this._suggestedQuality.complete();
480
- this._youtubeContainer.complete();
481
- this._playerVars.complete();
482
- this._destroyed.next();
483
- this._destroyed.complete();
484
- };
485
- /** See https://developers.google.com/youtube/iframe_api_reference#playVideo */
486
- YouTubePlayer.prototype.playVideo = function () {
487
- if (this._player) {
488
- this._player.playVideo();
489
- }
490
- else {
491
- this._getPendingState().playbackState = YT.PlayerState.PLAYING;
492
- }
493
- };
494
- /** See https://developers.google.com/youtube/iframe_api_reference#pauseVideo */
495
- YouTubePlayer.prototype.pauseVideo = function () {
496
- if (this._player) {
497
- this._player.pauseVideo();
498
- }
499
- else {
500
- this._getPendingState().playbackState = YT.PlayerState.PAUSED;
501
- }
502
- };
503
- /** See https://developers.google.com/youtube/iframe_api_reference#stopVideo */
504
- YouTubePlayer.prototype.stopVideo = function () {
505
- if (this._player) {
506
- this._player.stopVideo();
507
- }
508
- else {
509
- // It seems like YouTube sets the player to CUED when it's stopped.
510
- this._getPendingState().playbackState = YT.PlayerState.CUED;
511
- }
512
- };
513
- /** See https://developers.google.com/youtube/iframe_api_reference#seekTo */
514
- YouTubePlayer.prototype.seekTo = function (seconds, allowSeekAhead) {
515
- if (this._player) {
516
- this._player.seekTo(seconds, allowSeekAhead);
517
- }
518
- else {
519
- this._getPendingState().seek = { seconds: seconds, allowSeekAhead: allowSeekAhead };
520
- }
521
- };
522
- /** See https://developers.google.com/youtube/iframe_api_reference#mute */
523
- YouTubePlayer.prototype.mute = function () {
524
- if (this._player) {
525
- this._player.mute();
526
- }
527
- else {
528
- this._getPendingState().muted = true;
529
- }
530
- };
531
- /** See https://developers.google.com/youtube/iframe_api_reference#unMute */
532
- YouTubePlayer.prototype.unMute = function () {
533
- if (this._player) {
534
- this._player.unMute();
535
- }
536
- else {
537
- this._getPendingState().muted = false;
538
- }
539
- };
540
- /** See https://developers.google.com/youtube/iframe_api_reference#isMuted */
541
- YouTubePlayer.prototype.isMuted = function () {
542
- if (this._player) {
543
- return this._player.isMuted();
544
- }
545
- if (this._pendingPlayerState) {
546
- return !!this._pendingPlayerState.muted;
547
- }
548
- return false;
549
- };
550
- /** See https://developers.google.com/youtube/iframe_api_reference#setVolume */
551
- YouTubePlayer.prototype.setVolume = function (volume) {
552
- if (this._player) {
553
- this._player.setVolume(volume);
554
- }
555
- else {
556
- this._getPendingState().volume = volume;
557
- }
558
- };
559
- /** See https://developers.google.com/youtube/iframe_api_reference#getVolume */
560
- YouTubePlayer.prototype.getVolume = function () {
561
- if (this._player) {
562
- return this._player.getVolume();
563
- }
564
- if (this._pendingPlayerState && this._pendingPlayerState.volume != null) {
565
- return this._pendingPlayerState.volume;
566
- }
567
- return 0;
568
- };
569
- /** See https://developers.google.com/youtube/iframe_api_reference#setPlaybackRate */
570
- YouTubePlayer.prototype.setPlaybackRate = function (playbackRate) {
571
- if (this._player) {
572
- return this._player.setPlaybackRate(playbackRate);
573
- }
574
- else {
575
- this._getPendingState().playbackRate = playbackRate;
576
- }
577
- };
578
- /** See https://developers.google.com/youtube/iframe_api_reference#getPlaybackRate */
579
- YouTubePlayer.prototype.getPlaybackRate = function () {
580
- if (this._player) {
581
- return this._player.getPlaybackRate();
582
- }
583
- if (this._pendingPlayerState && this._pendingPlayerState.playbackRate != null) {
584
- return this._pendingPlayerState.playbackRate;
585
- }
586
- return 0;
587
- };
588
- /** See https://developers.google.com/youtube/iframe_api_reference#getAvailablePlaybackRates */
589
- YouTubePlayer.prototype.getAvailablePlaybackRates = function () {
590
- return this._player ? this._player.getAvailablePlaybackRates() : [];
591
- };
592
- /** See https://developers.google.com/youtube/iframe_api_reference#getVideoLoadedFraction */
593
- YouTubePlayer.prototype.getVideoLoadedFraction = function () {
594
- return this._player ? this._player.getVideoLoadedFraction() : 0;
595
- };
596
- /** See https://developers.google.com/youtube/iframe_api_reference#getPlayerState */
597
- YouTubePlayer.prototype.getPlayerState = function () {
598
- if (!this._isBrowser || !window.YT) {
599
- return undefined;
600
- }
601
- if (this._player) {
602
- return this._player.getPlayerState();
603
- }
604
- if (this._pendingPlayerState && this._pendingPlayerState.playbackState != null) {
605
- return this._pendingPlayerState.playbackState;
606
- }
607
- return YT.PlayerState.UNSTARTED;
608
- };
609
- /** See https://developers.google.com/youtube/iframe_api_reference#getCurrentTime */
610
- YouTubePlayer.prototype.getCurrentTime = function () {
611
- if (this._player) {
612
- return this._player.getCurrentTime();
613
- }
614
- if (this._pendingPlayerState && this._pendingPlayerState.seek) {
615
- return this._pendingPlayerState.seek.seconds;
616
- }
617
- return 0;
618
- };
619
- /** See https://developers.google.com/youtube/iframe_api_reference#getPlaybackQuality */
620
- YouTubePlayer.prototype.getPlaybackQuality = function () {
621
- return this._player ? this._player.getPlaybackQuality() : 'default';
622
- };
623
- /** See https://developers.google.com/youtube/iframe_api_reference#getAvailableQualityLevels */
624
- YouTubePlayer.prototype.getAvailableQualityLevels = function () {
625
- return this._player ? this._player.getAvailableQualityLevels() : [];
626
- };
627
- /** See https://developers.google.com/youtube/iframe_api_reference#getDuration */
628
- YouTubePlayer.prototype.getDuration = function () {
629
- return this._player ? this._player.getDuration() : 0;
630
- };
631
- /** See https://developers.google.com/youtube/iframe_api_reference#getVideoUrl */
632
- YouTubePlayer.prototype.getVideoUrl = function () {
633
- return this._player ? this._player.getVideoUrl() : '';
634
- };
635
- /** See https://developers.google.com/youtube/iframe_api_reference#getVideoEmbedCode */
636
- YouTubePlayer.prototype.getVideoEmbedCode = function () {
637
- return this._player ? this._player.getVideoEmbedCode() : '';
638
- };
639
- /** Gets an object that should be used to store the temporary API state. */
640
- YouTubePlayer.prototype._getPendingState = function () {
641
- if (!this._pendingPlayerState) {
642
- this._pendingPlayerState = {};
643
- }
644
- return this._pendingPlayerState;
645
- };
646
- /** Initializes a player from a temporary state. */
647
- YouTubePlayer.prototype._initializePlayer = function (player, state) {
648
- var playbackState = state.playbackState, playbackRate = state.playbackRate, volume = state.volume, muted = state.muted, seek = state.seek;
649
- switch (playbackState) {
650
- case YT.PlayerState.PLAYING:
651
- player.playVideo();
652
- break;
653
- case YT.PlayerState.PAUSED:
654
- player.pauseVideo();
655
- break;
656
- case YT.PlayerState.CUED:
657
- player.stopVideo();
658
- break;
659
- }
660
- if (playbackRate != null) {
661
- player.setPlaybackRate(playbackRate);
662
- }
663
- if (volume != null) {
664
- player.setVolume(volume);
665
- }
666
- if (muted != null) {
667
- muted ? player.mute() : player.unMute();
668
- }
669
- if (seek != null) {
670
- player.seekTo(seek.seconds, seek.allowSeekAhead);
671
- }
672
- };
673
- /** Gets an observable that adds an event listener to the player when a user subscribes to it. */
674
- YouTubePlayer.prototype._getLazyEmitter = function (name) {
675
- var _this = this;
676
- // Start with the stream of players. This way the events will be transferred
677
- // over to the new player if it gets swapped out under-the-hood.
678
- return this._playerChanges.pipe(
679
- // Switch to the bound event. `switchMap` ensures that the old event is removed when the
680
- // player is changed. If there's no player, return an observable that never emits.
681
- operators.switchMap(function (player) {
682
- return player ? rxjs.fromEventPattern(function (listener) {
683
- player.addEventListener(name, listener);
684
- }, function (listener) {
685
- // The API seems to throw when we try to unbind from a destroyed player and it doesn't
686
- // expose whether the player has been destroyed so we have to wrap it in a try/catch to
687
- // prevent the entire stream from erroring out.
688
- try {
689
- if (player.removeEventListener) {
690
- player.removeEventListener(name, listener);
691
- }
692
- }
693
- catch (_a) { }
694
- }) : rxjs.of();
695
- }),
696
- // By default we run all the API interactions outside the zone
697
- // so we have to bring the events back in manually when they emit.
698
- function (source) { return new rxjs.Observable(function (observer) { return source.subscribe({
699
- next: function (value) { return _this._ngZone.run(function () { return observer.next(value); }); },
700
- error: function (error) { return observer.error(error); },
701
- complete: function () { return observer.complete(); }
702
- }); }); },
703
- // Ensures that everything is cleared out on destroy.
704
- operators.takeUntil(this._destroyed));
705
- };
706
- return YouTubePlayer;
707
- }());
708
- YouTubePlayer.decorators = [
709
- { type: core.Component, args: [{
710
- selector: 'youtube-player',
711
- changeDetection: core.ChangeDetectionStrategy.OnPush,
712
- encapsulation: core.ViewEncapsulation.None,
713
- // This div is *replaced* by the YouTube player embed.
714
- template: '<div #youtubeContainer></div>'
715
- },] }
716
- ];
717
- YouTubePlayer.ctorParameters = function () { return [
718
- { type: core.NgZone },
719
- { type: Object, decorators: [{ type: core.Inject, args: [core.PLATFORM_ID,] }] }
720
- ]; };
721
- YouTubePlayer.propDecorators = {
722
- videoId: [{ type: core.Input }],
723
- height: [{ type: core.Input }],
724
- width: [{ type: core.Input }],
725
- startSeconds: [{ type: core.Input }],
726
- endSeconds: [{ type: core.Input }],
727
- suggestedQuality: [{ type: core.Input }],
728
- playerVars: [{ type: core.Input }],
729
- showBeforeIframeApiLoads: [{ type: core.Input }],
730
- ready: [{ type: core.Output }],
731
- stateChange: [{ type: core.Output }],
732
- error: [{ type: core.Output }],
733
- apiChange: [{ type: core.Output }],
734
- playbackQualityChange: [{ type: core.Output }],
735
- playbackRateChange: [{ type: core.Output }],
736
- youtubeContainer: [{ type: core.ViewChild, args: ['youtubeContainer',] }]
737
- };
738
- /** Listens to changes to the given width and height and sets it on the player. */
739
- function bindSizeToPlayer(playerObs, widthObs, heightObs) {
740
- return rxjs.combineLatest([playerObs, widthObs, heightObs])
741
- .subscribe(function (_b) {
742
- var _c = __read(_b, 3), player = _c[0], width = _c[1], height = _c[2];
743
- return player && player.setSize(width, height);
744
- });
745
- }
746
- /** Listens to changes from the suggested quality and sets it on the given player. */
747
- function bindSuggestedQualityToPlayer(playerObs, suggestedQualityObs) {
748
- return rxjs.combineLatest([
749
- playerObs,
750
- suggestedQualityObs
751
- ]).subscribe(function (_b) {
752
- var _c = __read(_b, 2), player = _c[0], suggestedQuality = _c[1];
753
- return player && suggestedQuality && player.setPlaybackQuality(suggestedQuality);
754
- });
755
- }
756
- /**
757
- * Returns an observable that emits the loaded player once it's ready. Certain properties/methods
758
- * won't be available until the iframe finishes loading.
759
- * @param onAbort Callback function that will be invoked if the player loading was aborted before
760
- * it was able to complete. Can be used to clean up any loose references.
761
- */
762
- function waitUntilReady(onAbort) {
763
- return operators.mergeMap(function (player) {
764
- if (!player) {
765
- return rxjs.of(undefined);
766
- }
767
- if (playerIsReady(player)) {
768
- return rxjs.of(player);
769
- }
770
- // Since removeEventListener is not on Player when it's initialized, we can't use fromEvent.
771
- // The player is not initialized fully until the ready is called.
772
- return new rxjs.Observable(function (emitter) {
773
- var aborted = false;
774
- var resolved = false;
775
- var onReady = function (event) {
776
- resolved = true;
777
- if (!aborted) {
778
- event.target.removeEventListener('onReady', onReady);
779
- emitter.next(event.target);
780
- }
781
- };
782
- player.addEventListener('onReady', onReady);
783
- return function () {
784
- aborted = true;
785
- if (!resolved) {
786
- onAbort(player);
787
- }
788
- };
789
- }).pipe(operators.take(1), operators.startWith(undefined));
790
- });
791
- }
792
- /** Create an observable for the player based on the given options. */
793
- function createPlayerObservable(youtubeContainer, videoIdObs, iframeApiAvailableObs, widthObs, heightObs, playerVarsObs, ngZone) {
794
- var playerOptions = rxjs.combineLatest([videoIdObs, playerVarsObs]).pipe(operators.withLatestFrom(rxjs.combineLatest([widthObs, heightObs])), operators.map(function (_b) {
795
- var _c = __read(_b, 2), constructorOptions = _c[0], sizeOptions = _c[1];
796
- var _d = __read(constructorOptions, 2), videoId = _d[0], playerVars = _d[1];
797
- var _e = __read(sizeOptions, 2), width = _e[0], height = _e[1];
798
- return videoId ? ({ videoId: videoId, playerVars: playerVars, width: width, height: height }) : undefined;
799
- }));
800
- return rxjs.combineLatest([youtubeContainer, playerOptions, rxjs.of(ngZone)])
801
- .pipe(skipUntilRememberLatest(iframeApiAvailableObs), operators.scan(syncPlayerState, undefined), operators.distinctUntilChanged());
802
- }
803
- /** Skips the given observable until the other observable emits true, then emit the latest. */
804
- function skipUntilRememberLatest(notifier) {
805
- return rxjs.pipe(operators.combineLatest(notifier), operators.skipWhile(function (_b) {
806
- var _c = __read(_b, 2), _ = _c[0], doneSkipping = _c[1];
807
- return !doneSkipping;
808
- }), operators.map(function (_b) {
809
- var _c = __read(_b, 1), value = _c[0];
810
- return value;
811
- }));
812
- }
813
- /** Destroy the player if there are no options, or create the player if there are options. */
814
- function syncPlayerState(player, _b) {
815
- var _c = __read(_b, 3), container = _c[0], videoOptions = _c[1], ngZone = _c[2];
816
- if (player && videoOptions && player.playerVars !== videoOptions.playerVars) {
817
- // The player needs to be recreated if the playerVars are different.
818
- player.destroy();
819
- }
820
- else if (!videoOptions) {
821
- if (player) {
822
- // Destroy the player if the videoId was removed.
823
- player.destroy();
824
- }
825
- return;
826
- }
827
- else if (player) {
828
- return player;
829
- }
830
- // Important! We need to create the Player object outside of the `NgZone`, because it kicks
831
- // off a 250ms setInterval which will continually trigger change detection if we don't.
832
- var newPlayer = ngZone.runOutsideAngular(function () { return new YT.Player(container, videoOptions); });
833
- newPlayer.videoId = videoOptions.videoId;
834
- newPlayer.playerVars = videoOptions.playerVars;
835
- return newPlayer;
836
- }
837
- /**
838
- * Call cueVideoById if the videoId changes, or when start or end seconds change. cueVideoById will
839
- * change the loaded video id to the given videoId, and set the start and end times to the given
840
- * start/end seconds.
841
- */
842
- function bindCueVideoCall(playerObs, videoIdObs, startSecondsObs, endSecondsObs, suggestedQualityObs, destroyed) {
843
- var cueOptionsObs = rxjs.combineLatest([startSecondsObs, endSecondsObs])
844
- .pipe(operators.map(function (_b) {
845
- var _c = __read(_b, 2), startSeconds = _c[0], endSeconds = _c[1];
846
- return ({ startSeconds: startSeconds, endSeconds: endSeconds });
847
- }));
848
- // Only respond to changes in cue options if the player is not running.
849
- var filteredCueOptions = cueOptionsObs
850
- .pipe(filterOnOther(playerObs, function (player) { return !!player && !hasPlayerStarted(player); }));
851
- // If the video id changed, there's no reason to run 'cue' unless the player
852
- // was initialized with a different video id.
853
- var changedVideoId = videoIdObs
854
- .pipe(filterOnOther(playerObs, function (player, videoId) { return !!player && player.videoId !== videoId; }));
855
- // If the player changed, there's no reason to run 'cue' unless there are cue options.
856
- var changedPlayer = playerObs.pipe(filterOnOther(rxjs.combineLatest([videoIdObs, cueOptionsObs]), function (_b, player) {
857
- var _c = __read(_b, 2), videoId = _c[0], cueOptions = _c[1];
858
- return !!player &&
859
- (videoId != player.videoId || !!cueOptions.startSeconds || !!cueOptions.endSeconds);
860
- }));
861
- rxjs.merge(changedPlayer, changedVideoId, filteredCueOptions)
862
- .pipe(operators.withLatestFrom(rxjs.combineLatest([playerObs, videoIdObs, cueOptionsObs, suggestedQualityObs])), operators.map(function (_b) {
863
- var _c = __read(_b, 2), _ = _c[0], values = _c[1];
864
- return values;
865
- }), operators.takeUntil(destroyed))
866
- .subscribe(function (_b) {
867
- var _c = __read(_b, 4), player = _c[0], videoId = _c[1], cueOptions = _c[2], suggestedQuality = _c[3];
868
- if (!videoId || !player) {
869
- return;
870
- }
871
- player.videoId = videoId;
872
- player.cueVideoById(Object.assign({ videoId: videoId, suggestedQuality: suggestedQuality }, cueOptions));
873
- });
874
- }
875
- function hasPlayerStarted(player) {
876
- var state = player.getPlayerState();
877
- return state !== YT.PlayerState.UNSTARTED && state !== YT.PlayerState.CUED;
878
- }
879
- function playerIsReady(player) {
880
- return 'getPlayerStatus' in player;
881
- }
882
- /** Combines the two observables temporarily for the filter function. */
883
- function filterOnOther(otherObs, filterFn) {
884
- return rxjs.pipe(operators.withLatestFrom(otherObs), operators.filter(function (_b) {
885
- var _c = __read(_b, 2), value = _c[0], other = _c[1];
886
- return filterFn(other, value);
887
- }), operators.map(function (_b) {
888
- var _c = __read(_b, 1), value = _c[0];
889
- return value;
890
- }));
891
- }
892
-
893
- /**
894
- * @license
895
- * Copyright Google LLC All Rights Reserved.
896
- *
897
- * Use of this source code is governed by an MIT-style license that can be
898
- * found in the LICENSE file at https://angular.io/license
899
- */
900
- var COMPONENTS = [YouTubePlayer];
901
- var YouTubePlayerModule = /** @class */ (function () {
902
- function YouTubePlayerModule() {
903
- }
904
- return YouTubePlayerModule;
905
- }());
906
- YouTubePlayerModule.decorators = [
907
- { type: core.NgModule, args: [{
908
- declarations: COMPONENTS,
909
- exports: COMPONENTS,
910
- },] }
911
- ];
912
-
913
- /**
914
- * @license
915
- * Copyright Google LLC All Rights Reserved.
916
- *
917
- * Use of this source code is governed by an MIT-style license that can be
918
- * found in the LICENSE file at https://angular.io/license
919
- */
920
-
921
- /**
922
- * Generated bundle index. Do not edit.
923
- */
924
-
925
- exports.YouTubePlayer = YouTubePlayer;
926
- exports.YouTubePlayerModule = YouTubePlayerModule;
927
-
928
- Object.defineProperty(exports, '__esModule', { value: true });
929
-
930
- })));
931
- //# sourceMappingURL=youtube-player.umd.js.map