Skip to content

Commit 54da277

Browse files
author
Nathan Tate
committed
feat(youtube-player) Add a demo to the dev-app
1 parent 809d991 commit 54da277

File tree

10 files changed

+135
-0
lines changed

10 files changed

+135
-0
lines changed

src/dev-app/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ ng_module(
7272
"//src/dev-app/tree",
7373
"//src/dev-app/typography",
7474
"//src/dev-app/virtual-scroll",
75+
"//src/dev-app/youtube-player",
7576
"//src/material/core",
7677
"@npm//@angular/router",
7778
],

src/dev-app/dev-app/dev-app-layout.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export class DevAppLayout {
7070
{name: 'Tree', route: '/tree'},
7171
{name: 'Typography', route: '/typography'},
7272
{name: 'Virtual Scrolling', route: '/virtual-scroll'},
73+
{name: 'YouTube Player', route: '/youtube-player'},
7374
{name: 'MDC Button', route: '/mdc-button'},
7475
{name: 'MDC Card', route: '/mdc-card'},
7576
{name: 'MDC Checkbox', route: '/mdc-checkbox'},

src/dev-app/dev-app/routes.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ export const DEV_APP_ROUTES: Routes = [
105105
path: 'virtual-scroll',
106106
loadChildren: 'virtual-scroll/virtual-scroll-demo-module#VirtualScrollDemoModule'
107107
},
108+
{
109+
path: 'youtube-player',
110+
loadChildren: 'youtube-player/youtube-player-demo-module#YouTubePlayerDemoModule',
111+
},
108112
{path: 'examples', loadChildren: 'examples-page/examples-page-module#ExamplesPageModule'},
109113
{path: '**', component: DevApp404},
110114
];

src/dev-app/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
<script src="systemjs/dist/system.js"></script>
3232
<script src="system-config.js"></script>
33+
<script src="https://www.youtube.com/iframe_api"></script>
3334
<script>
3435
// Workaround until https://github.com/angular/components/issues/13883 has been addressed.
3536
var module = {id: ''};

src/dev-app/system-config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ MATERIAL_PACKAGES.forEach(function(pkgName) {
105105
GOOGLE_MAPS_PACKAGES.forEach(function(pkgName) {
106106
configureEntryPoint('google-maps', pkgName);
107107
});
108+
configureEntryPoint('youtube-player');
108109

109110
/** Configures the specified package and its entry-point. */
110111
function configureEntryPoint(pkgName, entryPoint) {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
load("@io_bazel_rules_sass//:defs.bzl", "sass_binary")
4+
load("//tools:defaults.bzl", "ng_module")
5+
6+
ng_module(
7+
name = "youtube-player",
8+
srcs = glob(["**/*.ts"]),
9+
assets = [
10+
"youtube-player-demo.html",
11+
":youtube_player_demo_scss",
12+
],
13+
deps = [
14+
"//src/youtube-player",
15+
"//src/material/radio",
16+
"@npm//@angular/forms",
17+
"@npm//@angular/router",
18+
],
19+
)
20+
21+
sass_binary(
22+
name = "youtube_player_demo_scss",
23+
src = "youtube-player-demo.scss",
24+
)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {CommonModule} from '@angular/common';
10+
import {FormsModule} from '@angular/forms';
11+
import {MatRadioModule} from '@angular/material/radio';
12+
import {NgModule} from '@angular/core';
13+
import {RouterModule} from '@angular/router';
14+
import {YouTubePlayerModule} from '@angular/youtube-player';
15+
import {YouTubePlayerDemo} from './youtube-player-demo';
16+
17+
@NgModule({
18+
imports: [
19+
CommonModule,
20+
FormsModule,
21+
MatRadioModule,
22+
YouTubePlayerModule,
23+
RouterModule.forChild([{path: '', component: YouTubePlayerDemo}]),
24+
],
25+
declarations: [YouTubePlayerDemo],
26+
})
27+
export class YouTubePlayerDemoModule {
28+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<div>
2+
<h1>Basic Example</h1>
3+
<section>
4+
<div class="video-selection">
5+
<label class="video-selection-label">Pick the video:</label>
6+
<mat-radio-group aria-label="Select a video" [(ngModel)]="video">
7+
<mat-radio-button *ngFor="let video of videos" [value]="video">
8+
{{video.name}}
9+
</mat-radio-button>
10+
<mat-radio-button [value]="undefined">Unset</mat-radio-button>
11+
</mat-radio-group>
12+
</div>
13+
<p *ngIf="!apiLoaded">Loading youtube api...</p>
14+
<youtube-player *ngIf="apiLoaded" [videoId]="video && video.id"></youtube-player>
15+
</section>
16+
</div>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.video-selection {
2+
margin-bottom: 20px;
3+
4+
mat-radio-button {
5+
margin: 8px;
6+
}
7+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import {ChangeDetectorRef, Component} from '@angular/core';
2+
3+
declare global {
4+
interface Window {
5+
YT: typeof YT | undefined;
6+
onYouTubeIframeAPIReady: () => void;
7+
}
8+
}
9+
10+
interface Video {
11+
id: string;
12+
name: string;
13+
}
14+
15+
const VIDEOS: Video[] = [
16+
{
17+
id: 'PRQCAL_RMVo',
18+
name: 'Instructional',
19+
},
20+
{
21+
id: 'O0xx5SvjmnU',
22+
name: 'Angular Conf',
23+
},
24+
{
25+
id: 'invalidname',
26+
name: 'Invalid',
27+
},
28+
];
29+
30+
@Component({
31+
moduleId: module.id,
32+
selector: 'youtube-player-demo',
33+
templateUrl: 'youtube-player-demo.html',
34+
styleUrls: ['youtube-player-demo.css'],
35+
})
36+
export class YouTubePlayerDemo {
37+
video: Video | undefined = VIDEOS[0];
38+
videos = VIDEOS;
39+
apiLoaded = false;
40+
41+
constructor(private _ref: ChangeDetectorRef) {
42+
if (window.YT) {
43+
this.apiLoaded = true;
44+
return;
45+
}
46+
47+
window.onYouTubeIframeAPIReady = () => {
48+
this.apiLoaded = true;
49+
this._ref.detectChanges();
50+
};
51+
}
52+
}

0 commit comments

Comments
 (0)