All files / app/modals/mediacontrol mediacontrol.component.ts

3.44% Statements 1/29
0% Branches 0/7
0% Functions 0/12
4.16% Lines 1/24

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79                      1x                                                                                                                                      
import {Component, OnDestroy, OnInit} from '@angular/core';
import {MatBottomSheetRef} from "@angular/material/bottom-sheet";
import {BaseComponent} from "../../helpers/base/base.component";
import {DataService} from "../../services/data.service";
import {TimerService} from "../../services/timer.service";
 
@Component({
  selector: 'app-mediacontrol',
  templateUrl: './mediacontrol.component.html',
  styleUrls: ['./mediacontrol.component.css']
})
export class MediacontrolComponent extends BaseComponent implements OnInit, OnDestroy {
  musicProgress: number | undefined;
  musicIsPaused: boolean | undefined;
  musicIsFav: boolean | undefined;
 
 
  constructor(private _bottomSheetRef: MatBottomSheetRef<MediacontrolComponent>, private data: DataService, private timer: TimerService) {
    super()
  }
 
  // openLink(event: MouseEvent): void {
  //   this._bottomSheetRef.dismiss();
  //   event.preventDefault();
  // }
 
  close() {
    this._bottomSheetRef.dismiss();
  }
 
  ngOnInit() {
    this.data.currentMusicProgress.dieWith(this).subscribe(d => this.musicProgress = d);
    this.data.currentMusicIsPaused.dieWith(this).subscribe(d => this.musicIsPaused = d);
    this.data.currentMusicIsFav.dieWith(this).subscribe(d => this.musicIsFav = d);
  }
 
  setMusicProgress() {
    Iif (this.musicProgress !== undefined) {
      this.data.changeMusicProgress(this.musicProgress)
    }
  }
 
  toggleMusicPause() {
    Iif (this.musicIsPaused !== undefined) {
      if (!this.musicIsPaused) {
        this.timer.pauseTimer();
      }else{
        this.timer.startTimer();
      }
      this.data.changeMusicIsPaused(!this.musicIsPaused)
    }
  }
 
  toggleMusicFav() {
    Iif (this.musicIsFav !== undefined) {
      this.data.changeMusicIsFav(!this.musicIsFav)
    }
  }
 
  nextSong(){
    this.prevSong()
  }
 
  prevSong() {
    this.data.changeMusicProgress(0)
  }
 
  formatDuration(percentComplete: number | undefined, maxDurationInSeconds: number): string {
    if (percentComplete !== undefined) {
      const totalSecondsRemaining = maxDurationInSeconds * (percentComplete / 100);
      const minutes = Math.floor(totalSecondsRemaining / 60);
      const seconds = Math.floor(totalSecondsRemaining % 60);
      return `${minutes.toString().padStart(1, '0')}:${seconds.toString().padStart(2, '0')}`;
    } else {
      return "~?~";
    }
  }
}