Skip to content

Commit b572632

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

File tree

11 files changed

+144
-0
lines changed

11 files changed

+144
-0
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@
186186
/src/dev-app/tree/** @jelbourn
187187
/src/dev-app/typography/** @crisbeto
188188
/src/dev-app/virtual-scroll/** @mmalerba
189+
/src/dev-app/youtube-player/** @nathantate
189190

190191
# E2E app
191192
/src/e2e-app/* @jelbourn

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="demo-video-selection">
5+
<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+
.demo-video-selection {
2+
margin-bottom: 20px;
3+
4+
mat-radio-button {
5+
margin: 8px;
6+
}
7+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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 {ChangeDetectorRef, Component} from '@angular/core';
10+
11+
declare global {
12+
interface Window {
13+
YT: typeof YT | undefined;
14+
onYouTubeIframeAPIReady: () => void;
15+
}
16+
}
17+
18+
interface Video {
19+
id: string;
20+
name: string;
21+
}
22+
23+
const VIDEOS: Video[] = [
24+
{
25+
id: 'PRQCAL_RMVo',
26+
name: 'Instructional',
27+
},
28+
{
29+
id: 'O0xx5SvjmnU',
30+
name: 'Angular Conf',
31+
},
32+
{
33+
id: 'invalidname',
34+
name: 'Invalid',
35+
},
36+
];
37+
38+
@Component({
39+
moduleId: module.id,
40+
selector: 'youtube-player-demo',
41+
templateUrl: 'youtube-player-demo.html',
42+
styleUrls: ['youtube-player-demo.css'],
43+
})
44+
export class YouTubePlayerDemo {
45+
video: Video | undefined = VIDEOS[0];
46+
videos = VIDEOS;
47+
apiLoaded = false;
48+
49+
constructor(private _ref: ChangeDetectorRef) {
50+
if (window.YT) {
51+
this.apiLoaded = true;
52+
return;
53+
}
54+
55+
window.onYouTubeIframeAPIReady = () => {
56+
this.apiLoaded = true;
57+
this._ref.detectChanges();
58+
};
59+
}
60+
}

0 commit comments

Comments
 (0)