From 9af5d5d02b8414c235fc1786d2913ada8f09094d Mon Sep 17 00:00:00 2001 From: stickyPiston Date: Sat, 21 Sep 2019 17:09:56 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8F=97=20Created=20draft=20for=20AudioSer?= =?UTF-8?q?vice.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Not done yet... --- src/app/services/audio.service.ts | 22 +++++++++++++++++++++- src/app/services/data.service.ts | 2 +- 2 files changed, 22 insertions(+), 2 deletions(-) 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) { } /**