You have at least two Options. The first (simple) option makes use of an existing angular package, the second integrates the plyr js lib itself.
Option #1: Use angular npm package ngx-plyr
Use the newly created ngx-plyr npm package via
npm i plyr ngx-plyr
and follow the ngx-plyr github usage instructions or try this simple stackblitz demo.
Option #2: use plyr js lib
Integrate the plyr js lib into your angular project following these steps:
- Install plyr via yarn or npm
npm i plyr
Add into your angular.json scripts the plyr css and into scripts the plyr js e.g.:
...
"styles": [
"src/styles.scss",
"node_modules/plyr/dist/plyr.css"
],
"scripts": [
"node_modules/plyr/dist/plyr.js"
]
...
Add the video tag to your html template file, don't forget an id to link the template and the component! E.g:
<div class="container">
<video id='plyrID' controls crossorigin playsinline poster="https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-HD.jpg">
<source src="https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-576p.mp4" type="video/mp4" size="576">
<source src="https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-720p.mp4" type="video/mp4" size="720">
<source src="https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-1080p.mp4" type="video/mp4" size="1080">
<!-- Caption files -->
<track kind="captions" label="English" srclang="en" src="https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-HD.en.vtt"
default>
<track kind="captions" label="Français" srclang="fr" src="https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-HD.fr.vtt">
<!-- Fallback for browsers that don't support the <video> element -->
<a href="https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-576p.mp4" download>Download</a>
</video>
Create an instance of the plyr in your component e.g:
import { Component, OnInit} from '@angular/core';
import * as Plyr from 'plyr';
@Component({
selector: 'test',
templateUrl: './test.html',
})
export class TestComponent {
export class TestComponent implements OnInit {
public player;
ngOnInit() {
this.player = new Plyr('#plyrID', { captions: { active: true } });
}
}
Here is a stackblitz demo for direct usage of plyr js lib, with some minor changes to the above code (due to some stackblitz constraints).