<!DOCTYPE html>
<html>
<head>
<base href="." />
<title>angular2 playground</title>
<link rel="stylesheet" href="style.css" />
<script src="https://unpkg.com/core-js@2.4.1/client/shim.min.js"></script>
<script src="https://unpkg.com/zone.js/dist/zone.js"></script>
<script src="https://unpkg.com/zone.js/dist/long-stack-trace-zone.js"></script>
<script src="https://unpkg.com/reflect-metadata@0.1.3/Reflect.js"></script>
<script src="https://unpkg.com/systemjs@0.19.31/dist/system.js"></script>
<script src="config.js"></script>
<link href="https://vjs.zencdn.net/5.11/video-js.min.css" rel="stylesheet">
<!--
<script src="https://vjs.zencdn.net/5.11/video.min.js"></script>
-->
<script>
System.import('app')
.catch(console.error.bind(console));
</script>
</head>
<body>
<my-app>
loading...
</my-app>
</body>
</html>
/* Styles go here */
### Angular Starter Plunker - Typescript
System.config({
//use typescript for compilation
transpiler: 'typescript',
//typescript compiler options
typescriptOptions: {
emitDecoratorMetadata: true
},
paths: {
'npm:': 'https://unpkg.com/'
},
//map tells the System loader where to look for things
map: {
'app': './src',
'@angular/core': 'npm:@angular/core/bundles/core.umd.js',
'@angular/common': 'npm:@angular/common/bundles/common.umd.js',
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'@angular/http': 'npm:@angular/http/bundles/http.umd.js',
'@angular/router': 'npm:@angular/router/bundles/router.umd.js',
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
'@angular/core/testing': 'npm:@angular/core/bundles/core-testing.umd.js',
'@angular/common/testing': 'npm:@angular/common/bundles/common-testing.umd.js',
'@angular/compiler/testing': 'npm:@angular/compiler/bundles/compiler-testing.umd.js',
'@angular/platform-browser/testing': 'npm:@angular/platform-browser/bundles/platform-browser-testing.umd.js',
'@angular/platform-browser-dynamic/testing': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic-testing.umd.js',
'@angular/http/testing': 'npm:@angular/http/bundles/http-testing.umd.js',
'@angular/router/testing': 'npm:@angular/router/bundles/router-testing.umd.js',
'rxjs': 'npm:rxjs',
'typescript': 'npm:typescript@2.0.2/lib/typescript.js',
'videojs': 'npm:video.js@6.1.0/dist/video.min.js'
},
//packages defines our app package
packages: {
app: {
main: './main.ts',
defaultExtension: 'ts'
},
rxjs: {
defaultExtension: 'js'
},
videojs: {
defaultExtension: 'js'
}
}
});
//main entry point
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import {AppModule} from './app';
platformBrowserDynamic().bootstrapModule(AppModule)
//our root app component
import {Component, NgModule} from '@angular/core'
import {BrowserModule} from '@angular/platform-browser'
import {VideoJSComponent} from './videojs.component'
@Component({
selector: 'my-app',
template: `
<div>
<h2>VideoJS Angular 2 Component</h2>
<videojs *ngFor="let video of videos; let idx = index" [idx]="idx" [url]="video"></videojs>
</div>
`,
})
export class App {
// array of video elements
public videos = ['http://vjs.zencdn.net/v/oceans.mp4'];
constructor() {
}
}
@NgModule({
imports: [ BrowserModule ],
declarations: [ App, VideoJSComponent ],
bootstrap: [ App ]
})
export class AppModule {}
import {
Component,
OnInit,
OnDestroy,
ElementRef,
Input
} from '@angular/core';
//declare function videojs(id: any, options: any, ready:any): any;
import videojs from 'videojs'
@Component({
selector: 'videojs',
template: `
<video *ngIf="url" id="video_{{idx}}"
class="video-js vjs-default-skin vjs-big-play-centered vjs-16-9"
controls preload="auto" width="640" height="264">
<source [src]="url" type="video/mp4" />
</video>
`,
})
export class VideoJSComponent implements OnInit, OnDestroy {
// reference to the element itself, we use this to access events and methods
private _elementRef: ElementRef
// index to create unique ID for component
@Input() idx: string;
// video asset url
@Input() url: any;
// declare player var
private player: any;
// constructor initializes our declared vars
constructor(elementRef: ElementRef) {
this.url = false;
this.player = false;
}
ngOnInit() { }
// use ngAfterViewInit to make sure we initialize the videojs element
// after the component template itself has been rendered
ngAfterViewInit() {
// ID with which to access the template's video element
let el = 'video_' + this.idx;
// setup the player via the unique element ID
this.player = videojs(document.getElementById(el), {}, function() {
// Store the video object
var myPlayer = this, id = myPlayer.id();
// Make up an aspect ratio
var aspectRatio = 264/640;
// internal method to handle a window resize event to adjust the video player
function resizeVideoJS(){
var width = document.getElementById(id).parentElement.offsetWidth;
myPlayer.width(width);
myPlayer.height( width * aspectRatio );
}
// Initialize resizeVideoJS()
resizeVideoJS();
// Then on resize call resizeVideoJS()
window.onresize = resizeVideoJS;
});
}
}