UNPKG

ng5-yt-player

Version:

* [Description](#Description) * [Usage](#usage) * [Events](#Events) * [Download](#download)

2 lines (1 loc) 10.1 kB
{"version":3,"file":"ng5-yt-player.js","sources":["ts/ng5-yt-player.ts","ts/src/app/youtube-player/youtube-player.module.ts","ts/src/app/youtube-player/youtube-player.component.ts","ts/src/app/youtube-player/services/youtube-player.service.ts"],"sourcesContent":["/**\n * Generated bundle index. Do not edit.\n */\n\nexport {YouTubePlayerModule} from './public_api';\n\nexport {YoutubePlayerService as ɵb} from './src/app/youtube-player/services/youtube-player.service';\nexport {YoutubePlayerComponent as ɵa} from './src/app/youtube-player/youtube-player.component';","import { NgModule, CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA } from '@angular/core';\nimport { YoutubePlayerComponent } from './youtube-player.component';\nimport { YoutubePlayerService } from './services/youtube-player.service';\nimport { ModuleWithProviders } from '@angular/compiler/src/core';\nexport class YouTubePlayerModule {\nstatic decorators: DecoratorInvocation[] = [\n{ type: NgModule, args: [{\n declarations: [\n YoutubePlayerComponent\n ],\n schemas: [NO_ERRORS_SCHEMA, CUSTOM_ELEMENTS_SCHEMA],\n providers: [YoutubePlayerService],\n exports: [\n YoutubePlayerComponent\n ]\n}, ] },\n];\n/**\n * @nocollapse\n */\nstatic ctorParameters: () => ({type: any, decorators?: DecoratorInvocation[]}|null)[] = () => [\n];\n}\n\nfunction YouTubePlayerModule_tsickle_Closure_declarations() {\n/** @type {?} */\nYouTubePlayerModule.decorators;\n/**\n * @nocollapse\n * @type {?}\n */\nYouTubePlayerModule.ctorParameters;\n}\n\n\ninterface DecoratorInvocation {\n type: Function;\n args?: any[];\n}\n","import { Component, OnInit, EventEmitter, AfterContentInit, Output, Input, OnChanges, SimpleChanges } from '@angular/core';\nimport { YoutubePlayerService } from './services/youtube-player.service';\nimport { YT } from './models/youtube';\nconst /** @type {?} */ domEleId = 'player';\nexport class YoutubePlayerComponent implements AfterContentInit {\n videoId: string;\n height: number;\n width: number;\n playerParams: YT.PlayerVars;\n\n playerReadyEvent = new EventEmitter<YT.Player>();\n playerStateChangeEvent = new EventEmitter<YT.PlayerState>();\n\n domId;\n/**\n * @param {?} playerService\n */\nconstructor(private playerService: YoutubePlayerService) {\n this.domId = 'player-' + this.guid();\n }\n/**\n * @return {?}\n */\nngAfterContentInit() {\n const /** @type {?} */ playerOptions: YT.PlayerOptions = {\n videoId: this.videoId || '',\n height: this.height || 300,\n width: this.width || 300,\n playerVars: {\n ...this.playerParams,\n enablejsapi: 1\n }\n };\n\n this.playerService.loadPlayerApi();\n this.playerService.createPlayer(this.domId, playerOptions, this.playerReadyEvent, this.playerStateChangeEvent);\n }\n/**\n * @return {?}\n */\nguid() {\n/**\n * @return {?}\n */\nfunction s4() {\n return Math.floor((1 + Math.random()) * 0x10000)\n .toString(16)\n .substring(1);\n }\n return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();\n }\nstatic decorators: DecoratorInvocation[] = [\n{ type: Component, args: [{\n selector: 'ng5-youtube-player',\n template: `\n <div [id]=\"domId\"></div>\n `,\n styles: [`\n\n `]\n}, ] },\n];\n/**\n * @nocollapse\n */\nstatic ctorParameters: () => ({type: any, decorators?: DecoratorInvocation[]}|null)[] = () => [\n{type: YoutubePlayerService, },\n];\nstatic propDecorators: {[key: string]: DecoratorInvocation[]} = {\n'videoId': [{ type: Input },],\n'height': [{ type: Input },],\n'width': [{ type: Input },],\n'playerParams': [{ type: Input },],\n'playerReadyEvent': [{ type: Output },],\n'playerStateChangeEvent': [{ type: Output },],\n};\n}\n\nfunction YoutubePlayerComponent_tsickle_Closure_declarations() {\n/** @type {?} */\nYoutubePlayerComponent.decorators;\n/**\n * @nocollapse\n * @type {?}\n */\nYoutubePlayerComponent.ctorParameters;\n/** @type {?} */\nYoutubePlayerComponent.propDecorators;\n/** @type {?} */\nYoutubePlayerComponent.prototype.videoId;\n/** @type {?} */\nYoutubePlayerComponent.prototype.height;\n/** @type {?} */\nYoutubePlayerComponent.prototype.width;\n/** @type {?} */\nYoutubePlayerComponent.prototype.playerParams;\n/** @type {?} */\nYoutubePlayerComponent.prototype.playerReadyEvent;\n/** @type {?} */\nYoutubePlayerComponent.prototype.playerStateChangeEvent;\n/** @type {?} */\nYoutubePlayerComponent.prototype.domId;\n/** @type {?} */\nYoutubePlayerComponent.prototype.playerService;\n}\n\n\ninterface DecoratorInvocation {\n type: Function;\n args?: any[];\n}\n","import { Injectable, NgZone, EventEmitter } from '@angular/core';\nimport { YT } from '../../youtube-player/models/youtube';\n\nconst /** @type {?} */ $window: any = window;\nconst /** @type {?} */ iFrameSrc = 'http://www.youtube.com/iframe_api';\nexport class YoutubePlayerService {\n/**\n * @param {?} zone\n */\nconstructor(private zone: NgZone) { }\n/**\n * @param {?} domElementId\n * @param {?} playerOptions\n * @param {?} readyEvent\n * @param {?} stateChangeEvent\n * @return {?}\n */\ncreatePlayer(domElementId: string, playerOptions: YT.PlayerOptions,\n readyEvent: EventEmitter<YT.Player>, stateChangeEvent: EventEmitter<YT.PlayerState>) {\n return setInterval(() => {\n if ((typeof $window.YT !== 'undefined') && $window.YT && $window.YT.Player) {\n const /** @type {?} */ player = new $window.YT.Player(domElementId, {\n ...playerOptions,\n events: {\n onReady: (ev: YT.PlayerEvent) => {\n this.zone.run(() =>\n readyEvent.emit(ev.target));\n },\n onStateChange: (ev: YT.OnStateChangeEvent) => {\n /**\n * player state is 1 (playing), 2 for Pause. Reference https://developers.google.com/youtube/iframe_api_reference\n */\n this.zone.run(() => stateChangeEvent.emit(ev.data));\n }\n }\n });\n }\n }, 100);\n }\n/**\n * @return {?}\n */\nloadPlayerApi(): void {\n const /** @type {?} */ doc = $window.document;\n const /** @type {?} */ playerApi = doc.createElement('script');\n playerApi.type = 'text/javascript';\n playerApi.src = iFrameSrc;\n doc.body.appendChild(playerApi);\n }\nstatic decorators: DecoratorInvocation[] = [\n{ type: Injectable },\n];\n/**\n * @nocollapse\n */\nstatic ctorParameters: () => ({type: any, decorators?: DecoratorInvocation[]}|null)[] = () => [\n{type: NgZone, },\n];\n}\n\nfunction YoutubePlayerService_tsickle_Closure_declarations() {\n/** @type {?} */\nYoutubePlayerService.decorators;\n/**\n * @nocollapse\n * @type {?}\n */\nYoutubePlayerService.ctorParameters;\n/** @type {?} */\nYoutubePlayerService.prototype.zone;\n}\n\n\ninterface DecoratorInvocation {\n type: Function;\n args?: any[];\n}\n"],"names":[],"mappings":";;AGGA,MAAM,OAAA,GAAe,MAAA,CAAO;AAC5B,MAAM,SAAA,GAAY,mCAAA,CAAoC;AACtD,AAAA,MAAA,oBAAA,CAAA;;;;IAIA,WAAA,CADsB,IAAM,EAC5B;QADsB,IAAtB,CAAA,IAAsB,GAAA,IAAA,CAAM;KAAO;;;;;;;;IASnC,YAPG,CAAA,YAAA,EAAA,aAAA,EAQC,UAAmC,EAAE,gBAA8C,EADvF;QAEI,OAPO,WAAA,CAAY,MAOvB;YACM,IAAI,CAPC,OAAO,OAAA,CAAQ,EAAC,KAAM,WAAA,KAAgB,OAAA,CAAQ,EAAC,IAAK,OAAA,CAAQ,EAAC,CAAE,MAAC,EAAO;gBAQ1E,uBAPM,MAAA,GAAS,IAAI,OAAA,CAAQ,EAAC,CAAE,MAAC,CAAM,YAAC,EAO9C,MAAA,CAAA,MAAA,CAAA,EAAA,EACa,aAPC,EAMd,EAEU,MAAM,EAPE;wBAQN,OAAO,EAPE,CAAA,EAAS,KAO9B;4BACc,IAAI,CAPC,IAAC,CAAI,GAAC,CAAG,MAQZ,UAAU,CAPC,IAAC,CAAI,EAAC,CAAE,MAAC,CAAM,CAAC,CAAC;yBAQ/B;wBACD,aAAa,EAPE,CAAA,EAAS,KAOpC;;;;4BAIc,IAAI,CAPC,IAAC,CAAI,GAAC,CAAG,MAAM,gBAAA,CAAiB,IAAC,CAAI,EAAC,CAAE,IAAC,CAAI,CAAC,CAAC;yBAQrD;qBACF,EAAX,CAAA,CANU,CAAC;aAQJ;SACF,EAPE,GAAA,CAAI,CAAC;KAQT;;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