videojs angular code example
Example: videojs example angular
import { Component, ElementRef, Input, OnDestroy, OnInit, ViewChild, ViewEncapsulation } from '@angular/core';
import videojs from 'video.js';
@Component({
selector: 'app-vjs-player',
template: `
<video #target class="video-js" controls muted playsinline preload="none"></video>
`,
styleUrls: [
'./vjs-player.component.css'
],
encapsulation: ViewEncapsulation.None,
})
export class VjsPlayerComponent implements OnInit, OnDestroy {
@ViewChild('target', {static: true}) target: ElementRef;
@Input() options: {
fluid: boolean,
aspectRatio: string,
autoplay: boolean,
sources: {
src: string,
type: string,
}[],
};
player: videojs.Player;
constructor(
private elementRef: ElementRef,
) { }
ngOnInit() {
this.player = videojs(this.target.nativeElement, this.options, function onPlayerReady() {
console.log('onPlayerReady', this);
});
}
ngOnDestroy() {
if (this.player) {
this.player.dispose();
}
}
}