# HG changeset patch # User Lucas Thompson # Date 1480606857 0 # Node ID f6e58c2accb0dcba22b52ff165c3b5857f1a6eb6 # Parent e58fb181a11de9d3431ceec00ca296c4b40a7a64 Move service into subdirectory. diff -r e58fb181a11d -r f6e58c2accb0 src/app/app.component.ts --- a/src/app/app.component.ts Thu Dec 01 14:05:49 2016 +0000 +++ b/src/app/app.component.ts Thu Dec 01 15:40:57 2016 +0000 @@ -1,5 +1,5 @@ import {Component} from '@angular/core'; -import {AudioPlayerService} from "./services/audio-player.service"; +import {AudioPlayerService} from "./services/audio-player/audio-player.service"; @Component({ selector: 'app-root', diff -r e58fb181a11d -r f6e58c2accb0 src/app/app.module.ts --- a/src/app/app.module.ts Thu Dec 01 14:05:49 2016 +0000 +++ b/src/app/app.module.ts Thu Dec 01 15:40:57 2016 +0000 @@ -8,7 +8,7 @@ import { WaveformComponent } from './waveform/waveform.component'; import { AudioFileOpenComponent } from './audio-file-open/audio-file-open.component'; import { PlaybackControlComponent } from './playback-control/playback-control.component'; -import { AudioPlayerService } from "./services/audio-player.service"; +import { AudioPlayerService } from "./services/audio-player/audio-player.service"; function createAudioContext(): AudioContext { return new ( diff -r e58fb181a11d -r f6e58c2accb0 src/app/playback-control/playback-control.component.ts --- a/src/app/playback-control/playback-control.component.ts Thu Dec 01 14:05:49 2016 +0000 +++ b/src/app/playback-control/playback-control.component.ts Thu Dec 01 15:40:57 2016 +0000 @@ -1,5 +1,5 @@ import {Component, OnInit} from '@angular/core'; -import {AudioPlayerService} from "../services/audio-player.service"; +import {AudioPlayerService} from "../services/audio-player/audio-player.service"; @Component({ selector: 'app-playback-control', diff -r e58fb181a11d -r f6e58c2accb0 src/app/services/audio-player.service.spec.ts --- a/src/app/services/audio-player.service.spec.ts Thu Dec 01 14:05:49 2016 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -/* tslint:disable:no-unused-variable */ - -import { TestBed, async, inject } from '@angular/core/testing'; -import { AudioPlayerService } from './audio-player.service'; - -describe('AudioPlayerService', () => { - beforeEach(() => { - TestBed.configureTestingModule({ - providers: [AudioPlayerService] - }); - }); - - it('should ...', inject([AudioPlayerService], (service: AudioPlayerService) => { - expect(service).toBeTruthy(); - })); -}); diff -r e58fb181a11d -r f6e58c2accb0 src/app/services/audio-player.service.ts --- a/src/app/services/audio-player.service.ts Thu Dec 01 14:05:49 2016 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -import {Injectable, Inject} from '@angular/core'; - -@Injectable() -export class AudioPlayerService { - - constructor(@Inject(HTMLAudioElement) private audioElement: HTMLAudioElement /* TODO probably shouldn't play audio this way */, - @Inject('AudioContext') private audioContext: AudioContext) { - } - - getCurrentTime(): number { - return this.audioElement.currentTime; - } - - isPlaying(): boolean { - return !this.audioElement.paused; - } - - decodeAudioData(buffer: ArrayBuffer): Promise { - return new Promise((res, rej) => this.audioContext.decodeAudioData(buffer, res, rej)); - } - - loadAudioFromUrl(url: string): void { - this.audioElement.pause(); - this.audioElement.src = url; - } - - togglePlaying(): void { - this.isPlaying() ? this.audioElement.pause() : this.audioElement.play(); - } - - setVolume(value: number): void { - this.audioElement.volume = value; // TODO check bounds? - } - - seekBy(seconds: number): void { - // TODO some kind of error handling? - this.audioElement.currentTime += seconds; - } - - seekToStart(): void { - this.audioElement.currentTime = 0; - } - - seekToEnd(): void { - this.audioElement.currentTime = this.getDuration(); - } - - getDuration(): number { - return this.audioElement.duration; - } -} diff -r e58fb181a11d -r f6e58c2accb0 src/app/services/audio-player/audio-player.service.spec.ts --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/app/services/audio-player/audio-player.service.spec.ts Thu Dec 01 15:40:57 2016 +0000 @@ -0,0 +1,16 @@ +/* tslint:disable:no-unused-variable */ + +import { TestBed, async, inject } from '@angular/core/testing'; +import { AudioPlayerService } from './audio-player.service'; + +describe('AudioPlayerService', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [AudioPlayerService] + }); + }); + + it('should ...', inject([AudioPlayerService], (service: AudioPlayerService) => { + expect(service).toBeTruthy(); + })); +}); diff -r e58fb181a11d -r f6e58c2accb0 src/app/services/audio-player/audio-player.service.ts --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/app/services/audio-player/audio-player.service.ts Thu Dec 01 15:40:57 2016 +0000 @@ -0,0 +1,51 @@ +import {Injectable, Inject} from '@angular/core'; + +@Injectable() +export class AudioPlayerService { + + constructor(@Inject(HTMLAudioElement) private audioElement: HTMLAudioElement /* TODO probably shouldn't play audio this way */, + @Inject('AudioContext') private audioContext: AudioContext) { + } + + getCurrentTime(): number { + return this.audioElement.currentTime; + } + + isPlaying(): boolean { + return !this.audioElement.paused; + } + + decodeAudioData(buffer: ArrayBuffer): Promise { + return new Promise((res, rej) => this.audioContext.decodeAudioData(buffer, res, rej)); + } + + loadAudioFromUrl(url: string): void { + this.audioElement.pause(); + this.audioElement.src = url; + } + + togglePlaying(): void { + this.isPlaying() ? this.audioElement.pause() : this.audioElement.play(); + } + + setVolume(value: number): void { + this.audioElement.volume = value; // TODO check bounds? + } + + seekBy(seconds: number): void { + // TODO some kind of error handling? + this.audioElement.currentTime += seconds; + } + + seekToStart(): void { + this.audioElement.currentTime = 0; + } + + seekToEnd(): void { + this.audioElement.currentTime = this.getDuration(); + } + + getDuration(): number { + return this.audioElement.duration; + } +}