view src/app/app.component.ts @ 44:13f5f228ed98

Add a component for the feature extraction menu, and start setting up some comms with the worker. Currently populating a select box with list of extractors from hardcoded server.
author Lucas Thompson <dev@lucas.im>
date Fri, 02 Dec 2016 16:55:14 +0000
parents f6e58c2accb0
children 933c64ebcd13
line wrap: on
line source
import {Component} from '@angular/core';
import {AudioPlayerService} from "./services/audio-player/audio-player.service";

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  audioBuffer: AudioBuffer; // TODO consider revising

  constructor(private audioService: AudioPlayerService) {}

  onFileOpened(file: File) {
    const reader: FileReader = new FileReader();
    const mimeType = file.type;
    reader.onload = (event: any) => {
      this.audioService.loadAudioFromUrl(
        URL.createObjectURL(new Blob([event.target.result], {type: mimeType}))
      );
      // TODO use a rxjs/Subject instead?
      this.audioService.decodeAudioData(event.target.result).then(audioBuffer => {
        this.audioBuffer = audioBuffer;
      });
    };
    reader.readAsArrayBuffer(file);
  }
}