File
Implements
Metadata
selector |
[video-player] |
styleUrls |
./video-player.component.scss |
templateUrl |
./video-player.component.html |
Index
Properties
|
|
Methods
|
|
Inputs
|
|
videoDescription
|
Type : string
|
|
Methods
Private
getVideoType
|
getVideoType(video: any)
|
|
Parameters :
Name |
Type |
Optional |
video |
any
|
No
|
|
Public
openModal
|
openModal(templateRef)
|
|
Parameters :
Name |
Optional |
templateRef |
No
|
|
Public
setUpMediaMasterVideo
|
setUpMediaMasterVideo(video: any)
|
|
Parameters :
Name |
Type |
Optional |
video |
any
|
No
|
|
Public
setUpYoutubeVideo
|
setUpYoutubeVideo(video: any)
|
|
Parameters :
Name |
Type |
Optional |
video |
any
|
No
|
|
videoObject
|
Type : any
|
Default value : {}
|
|
import { Component, OnInit, Input, AfterViewInit } from '@angular/core';
import { UtilService } from 'src/app/core/services/util-service/util.service';
import { IdGeneratorService } from 'src/app/core/services/id-generator.service';
import { DomSanitizer } from '@angular/platform-browser';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { ConstantsService } from 'src/app/shared/constants/constants.service';
import { fromEvent } from 'rxjs';
import { map } from 'rxjs/operators';
type videoType = 'AKAMAI' | 'MEDIA_MASTER' | 'YOUTUBE';
@Component({
selector: '[video-player]',
templateUrl: './video-player.component.html',
styleUrls: ['./video-player.component.scss']
})
export class VideoPlayerComponent implements OnInit {
@Input() videoJSON: any;
@Input() videoDescription: string;
videoType: videoType;
videoID: string;
videoObject: any = {};
constructor(private util: UtilService,
private sanitizer: DomSanitizer,
private modalService: NgbModal,
private constants: ConstantsService,
private idService: IdGeneratorService) { }
ngOnInit() {
this.videoID = `video-id-${this.idService.getId()}`;
this.videoType = this.getVideoType(this.videoJSON);
// Akamai player does require any special fields to be set, will take the entire videoJSON as input
if (this.videoType === 'YOUTUBE') {
this.setUpYoutubeVideo(this.videoJSON);
} else if (this.videoType === 'MEDIA_MASTER') {
this.setUpMediaMasterVideo(this.videoJSON);
}
}
private getVideoType(video: any): videoType {
const isAkamai = this.util.extract(video, 'Type') === 'akamaiplayer';
// If this only exists on the youtube video
const isYoutube = !!this.util.extract(video, 'VidDisplay');
if (isAkamai) {
return 'AKAMAI';
} else if (isYoutube) {
return 'YOUTUBE';
} else {
return 'MEDIA_MASTER';
}
}
public openModal(templateRef): void {
this.modalService.open(templateRef, { size: 'lg', centered: true });
}
public setUpMediaMasterVideo(video: any): void {
this.videoObject['URL'] = this.util.extract(video, 'Url');
this.videoObject['MIME_TYPE'] = this.util.extract(video, 'MimeType');
this.videoObject['IMG'] = this.constants.VIDEO_PLAYER_PREVIEW_IMG;
}
public setUpYoutubeVideo(video: any): void {
const youtubeVideoId = this.util.extract(video, 'Link');
this.videoObject['URL'] = this.sanitizer.bypassSecurityTrustResourceUrl(`https://www.youtube.com/embed/${youtubeVideoId}?autoplay=1&enablejsapi=1`);
this.videoObject['IMG'] = `https://img.youtube.com/vi/${youtubeVideoId}/0.jpg`;
}
}
<ng-container [ngSwitch]="videoType">
<div *ngSwitchCase="'AKAMAI'" class="video-wrapper">
<akamai-media-player class="akamai-player" [akamaiMedia]="videoJSON" [ampId]="videoID"></akamai-media-player>
<p>{{videoDescription}}</p>
</div>
<div *ngSwitchDefault class="video-wrapper">
<button type="button" (click)="openModal(videoID)" class="video">
<img [src]="videoObject.IMG">
<i class="fas fa-play video-play-icon"></i>
</button>
<p>{{videoDescription}}</p>
</div>
</ng-container>
<ng-template #videoID let-modal>
<div class="modal-body">
<div class="videoContainer">
<iframe *ngIf="videoType === 'YOUTUBE'" allowfullscreen
allow='autoplay'
[id]="iframeId"
[src]="videoObject.URL">
</iframe >
<video *ngIf="videoType === 'MEDIA_MASTER'" controls class="">
<source [src]="videoObject.URL"
[type]="videoObject.MIME_TYPE">
</video>
</div>
</div>
</ng-template>
@import "src/app/styles/helpers";
.modal-body {
padding: 0;
}
.video-wrapper {
height: 100%;
}
.videoContainer {
position: relative;
@include aspect-ratio(16 9, "iframe, video");
iframe {
position: absolute;
top: 0; left: 0;
border: 0;
width: 100%;
height: 100%;
}
}
.video {
width: 100%;
height: 100%;
border: none;
outline: none;
@include font-size(40);
@include aspect-ratio(16 9);
img {
cursor: pointer;
}
&:hover {
.video-play-icon {
background-color: $dark-blue;
}
}
}
.video-play-icon {
position: absolute;
background-color: $blue;
padding: 16px;
bottom: 0;
left: 0;
font-size: .9rem;
color: white;
cursor: pointer;
&:hover {
background-color: $dark-blue;
}
}
.play-img {
position: absolute;
}
p {
@include font-size(18);
color: $blue;
}
Legend
Html element with directive