Implement audio volume and loop properties

This commit is contained in:
PizZaKatZe 2021-03-11 22:34:49 +01:00
parent 132c6c9ad6
commit fdbcd98a9a
3 changed files with 14 additions and 7 deletions

View file

@ -41,7 +41,7 @@ class AudioManager {
this.audioPlayerVol.value = '' + this.volume;
}
public playAudio(url: string|number|boolean, mapDirUrl: string, loop=false): void {
public playAudio(url: string|number|boolean, mapDirUrl: string, volume: number|undefined, loop=false): void {
const audioPath = url as string;
let realAudioPath = '';
@ -53,7 +53,7 @@ class AudioManager {
realAudioPath = mapDirUrl + '/' + url;
}
this.loadAudio(realAudioPath);
this.loadAudio(realAudioPath, volume);
if (loop) {
this.loop();
@ -100,8 +100,7 @@ class AudioManager {
localStorage.setItem('volume', '' + volume);
}
private loadAudio(url: string): void {
private loadAudio(url: string, volume: number|undefined): void {
this.load();
/* Solution 1, remove whole audio player */
@ -119,6 +118,7 @@ class AudioManager {
this.audioPlayerElem.append(srcElem);
this.audioPlayerDiv.append(this.audioPlayerElem);
this.volume = volume ? Math.min(volume, this.volume) : this.volume;
this.changeVolume();
this.audioPlayerElem.play();