import { Component } from '@angular/core' ; import { AudioService } from '../../services/audio.service' ; import { CloudService } from '../../services/cloud.service' ; import { StreamState } from '../../interfaces/stream-state' ; import { AuthService } from '../../services/auth.service' ; @ Component ( { selector : 'app-player' , templateUrl : './player.component.html' , styleUrls : [ './player.component.scss' ] } ) export class PlayerComponent { files : Array < any > = [ ] ; state : StreamState ; currentFile : any = { } ; constructor ( private audioService , cloudService , public auth ) { cloudService . getFiles ( ) . subscribe ( files => { this . files = files ; } ) ; this . audioService . getState ( ) . subscribe ( state => { this . state = state ; } ) ; } playStream ( url ) { this . audioService . playStream ( url ) . subscribe ( events => { } ) ; } openFile ( file , index ) { this . currentFile = { index , file } ; this . audioService . stop ( ) ; this . playStream ( file . url ) ; } pause ( ) { this . audioService . pause ( ) ; } play ( ) { this . audioService . play ( ) ; } stop ( ) { this . audioService . stop ( ) ; } next ( ) { const index = this . currentFile . index + 1 ; const file = this . files [ index ] ; this . openFile ( file , index ) ; } previous ( ) { const index = this . currentFile . index - 1 ; const file = this . files [ index ] ; this . openFile ( file , index ) ; } isFirstPlaying ( ) { return this . currentFile . index === 0 ; } isLastPlaying ( ) { return this . currentFile . index === this . files . length - 1 ; } onSliderChangeEnd ( change ) { this . audioService . seekTo ( change . value ) ; } }