mat-video is an Angular component for playing videos. It has all the features you would expect from a standard video player, all in an extremely light package. The video player is designed to be flexible and easy to use; you can be up and running in less than 5 minutes!
It was built for modern browsers using TypeScript, CSS3 and HTML5 with Angular & Material 5/6/7+.
See the changelog for recent changes.
If you wish to contribute, please fill out the pull request template. For issues, please fill out the issue template before submitting.
- Native HTML5 video player
- Easy to use
- Play/Pause
- Seeking
- Volume
- Autoplay
- Preload
- Looping
- Scaling
- Fullscreen
- Download
- Buffering spinners
- Poster image
- Subtitles and text tracks
- Multiple media sources
- Customizable controls
- Material theming
- Keyboard shortcuts
- Fixed and responsive sizing
- Supports Chrome, Firefox, Safari, and Edge
mat-video requires Angular Material as a peer dependency, including animations.
npm install --save @angular/material @angular/cdk @angular/animations hammerjs
Add the following import to src/polyfills.ts
:
import 'hammerjs';
To use mat-video in your project install it via npm:
npm install --save mat-video
Add the following to your module:
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { MatVideoModule } from 'mat-video';
@NgModule({
imports: [
BrowserAnimationsModule,
MatVideoModule
],
})
export class AppModule { }
Finally, include an Angular Material theme in styles.css
, or via a <link>
element in index.html
.
@import '~@angular/material/prebuilt-themes/indigo-pink.css';
A minimal example is quite simple, in your HTML file:
<mat-video src="localOrRemoteVideo.mp4"></mat-video>
A slightly more customized example, in your HTML file:
<mat-video title="My Tutorial Title" [autoplay]="true" [preload]="true" [fullscreen]="true" [download]="false" color="accent" spinner="spin" poster="image.jpg">
<source matVideoSource src="tutorial.mp4" type="video/mp4">
<source src="tutorial.webm" type="video/webm">
<track matVideoTrack src="subtitles_en.vtt" kind="subtitles" srclang="en" label="English">
<track src="subtitles_no.vtt" kind="subtitles" srclang="no" label="Norwegian">
</mat-video>
Attribute | Type | Description | Default |
---|---|---|---|
src | string | Path or URL to a video | null |
title | string | Title for the video | null |
autoplay | boolean | Whether the video should autoplay | false |
preload | boolean | Whether the video should preload | true |
loop | boolean | Whether the video should loop | false |
quality | boolean | Whether the video will have a quality indicator | true |
download | boolean | Whether the video will have a download option | false |
fullscreen | boolean | Whether the video will have a fullscreen option | true |
keyboard | boolean | Whether the player will have keyboard shortcuts | true |
color | ThemePalette | Material theme color palette for the sliders | primary |
spinner | string | Use 'spin', 'dot', 'split-ring', 'hourglass', or pass your own buffering spinner class | spin |
poster | string | Path or URL to a poster image | null |
In addition, source and track elements are supported by mat-video.
The matVideoSource attribute can be used on the source tag to automatically reload the video when the source changes.
The matVideoTrack attribute can be used on the track tag to automatically reload the video when the track changes.
Listening to video events can be accomplished by directly accessing the video tag within mat-video.
In your HTML file:
<mat-video #video src="localOrRemoteVideo.mp4"></mat-video>
In your TS file:
export class SampleComponent implements OnInit {
@ViewChild('video') matVideo: MatVideoComponent;
video: HTMLVideoElement;
constructor(private renderer: Renderer2) { }
ngOnInit(): void {
this.video = this.matVideo.getVideoTag();
// Use Angular renderer or addEventListener to listen for standard HTML5 video events
this.renderer.listen(this.video, 'ended', () => console.log('video ended'));
this.video.addEventListener('ended', () => console.log('video ended'));
}
}
This API feature is considered experimental, and is subject to change.
mat-video is an open-source project developed by Nicholas Koehler.
Special thanks to mediapack-me for responsive assistance.