ucap-doc/documents/업무/6월/2째주/backup/sound-viewer.component.ts
Park Byung Eun 7dcec1aaad sync
2020-06-09 09:12:32 +09:00

105 lines
2.3 KiB
TypeScript

import {
Component,
OnInit,
Input,
Output,
EventEmitter,
ViewChild,
ElementRef
} from '@angular/core';
import { ucapAnimations } from '../../animations';
import { FileInfo } from '@ucap-webmessenger/protocol-file';
import { MatSlider, MatSliderChange } from '@angular/material/slider';
import { FileDownloadItem } from '@ucap-webmessenger/api';
@Component({
selector: 'ucap-sound-viewer',
templateUrl: './sound-viewer.component.html',
styleUrls: ['./sound-viewer.component.scss'],
animations: ucapAnimations
})
export class SoundViewerComponent implements OnInit {
@Input()
fileInfo: FileInfo;
@Input()
fileName: string;
@Input()
fileDownloadUrl: string;
@Output()
download = new EventEmitter<FileDownloadItem>();
@Output()
closed = new EventEmitter<void>();
@ViewChild('audioPlayer', { static: true })
audioPlayer: ElementRef<HTMLAudioElement>;
@ViewChild('timeSlider', { static: true })
timeSlider: MatSlider;
playing = false;
duration = 0.01;
currentTime = 0;
volume = 0.1;
loading = false;
fileDownloadItem: FileDownloadItem;
constructor() {}
ngOnInit() {}
onClickPlayOrPause(): void {
if (this.loading) {
return;
}
if (this.audioPlayer.nativeElement.paused) {
this.audioPlayer.nativeElement.play();
} else {
this.currentTime = this.audioPlayer.nativeElement.currentTime;
this.audioPlayer.nativeElement.pause();
}
}
onChangeTimeSlider(e: MatSliderChange): void {
this.audioPlayer.nativeElement.currentTime = e.value;
}
onPlayingAudio(): void {
this.playing = true;
// this.duration = Math.floor(this.audioPlayer.nativeElement.duration);
}
onPauseAudio(): void {
this.playing = false;
}
onTimeUpdateAudio(): void {
this.currentTime = Math.floor(this.audioPlayer.nativeElement.currentTime);
}
onVolumeChangeAudio(): void {
this.volume = Math.floor(this.audioPlayer.nativeElement.volume);
}
onLoadStartAudio(): void {
this.loading = true;
}
onLoadedDataAudio(): void {
this.loading = false;
this.duration = Math.floor(this.audioPlayer.nativeElement.duration);
}
onClickDownload(): void {
this.fileDownloadItem = new FileDownloadItem();
this.download.emit(this.fileDownloadItem);
}
onClickClose(): void {
this.closed.emit();
}
}