diff src/app/app.module.ts @ 31:f6ea31a3b1a3

Encapsulate audio playing and decoding logic in a ng2 service, provided by the root module.
author Lucas Thompson <dev@lucas.im>
date Wed, 30 Nov 2016 10:21:27 +0000
parents 3e96bcbfa5c5
children f6e58c2accb0
line wrap: on
line diff
--- a/src/app/app.module.ts	Wed Nov 30 10:18:03 2016 +0000
+++ b/src/app/app.module.ts	Wed Nov 30 10:21:27 2016 +0000
@@ -4,10 +4,18 @@
 import { HttpModule } from '@angular/http';
 
 import { AppComponent } from './app.component';
-import {MaterialModule} from "@angular/material";
+import { MaterialModule } from "@angular/material";
 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";
+
+function createAudioContext(): AudioContext {
+  return new (
+    (window as any).AudioContext
+    || (window as any).webkitAudioContext
+  )();
+}
 
 @NgModule({
   declarations: [
@@ -23,7 +31,9 @@
     MaterialModule.forRoot()
   ],
   providers: [
-    {provide: 'piper-server-uri', useValue: 'ws://not/a/real/path'}
+    {provide: HTMLAudioElement, useValue: new Audio()}, // TODO use something more generic than HTMLAudioElement
+    {provide: 'AudioContext', useValue: createAudioContext()}, // use a string token, Safari doesn't seem to like AudioContext
+    AudioPlayerService
   ],
   bootstrap: [AppComponent]
 })