官网参考地址:https://videogular.github.io/videogular2/docs/getting-started/how-videogular-works.html
npm install videogular2 --save
npm install @types/core-js --save-dev
import {VgCoreModule} from 'videogular2/core';
import {VgControlsModule} from 'videogular2/controls';
import {VgOverlayPlayModule} from 'videogular2/overlay-play';
import {VgBufferingModule} from 'videogular2/buffering';
@NgModule({
declarations: [],
imports: [
VgCoreModule,
VgControlsModule,
VgOverlayPlayModule,
VgBufferingModule,
],
providers:[]
})
export class HomeModule { }
<vg-player (onPlayerReady)="onPlayerReady($event)">
<video [vgMedia]="media" #media id="bg_video" crossorigin autoplay preload="auto">
<source src="../../../../assets/video/02.mp4" type="video/mp4">
</video>
</vg-player>
import { Component, ViewChild, OnInit, AfterViewInit, AfterViewChecked, Inject } from '@angular/core';
import { VgAPI } from 'videogular2/core';
@Component({
selector: 'app-dashboard',
templateUrl: './dashboard.component.html',
styleUrls: ['./dashboard.component.scss']
})
export class DashboardComponent implements OnInit, AfterViewInit {
vgApi: VgAPI;
ngAfterViewInit() {
this.vgApi.subscriptions.canPlayThrough.subscribe(() => {
let timer = setInterval(() => {
if (this.vgApi.state === 'playing') {
clearInterval(timer);
} else {
this.vgApi.play();
}
}, 1000);
});
}
//初始化
onPlayerReady(api: VgAPI) {
this.vgApi = api;
}
}