diff --git a/src/app/services/audio.service.ts b/src/app/services/audio.service.ts index f7f1c41..8759c25 100644 --- a/src/app/services/audio.service.ts +++ b/src/app/services/audio.service.ts @@ -1,9 +1,29 @@ import { Injectable } from '@angular/core'; +import { DataService } from './data.service'; @Injectable({ providedIn: 'root' }) export class AudioService { - constructor() { } + player = new Audio(); + + currentlyPlaying; + + constructor(private data: DataService) { } + + play() { + this.player.play(); + } + + pause() { + this.player.pause(); + } + + setSong(id: number) { + this.data.getSong(id).subscribe((res: any) => { + this.player.src = this.data.apiUrl + '/play/' + res.result[0].path; + this.currentlyPlaying = id; + }); + } } diff --git a/src/app/services/data.service.ts b/src/app/services/data.service.ts index b885774..02d1bcb 100644 --- a/src/app/services/data.service.ts +++ b/src/app/services/data.service.ts @@ -13,7 +13,7 @@ import { Observable } from 'rxjs'; }) export class DataService { - private apiUrl = 'http://localhost:673'; + public apiUrl = 'http://localhost:673'; constructor(private http: HttpClient) { } /**