# HG changeset patch # User Lucas Thompson # Date 1477575877 -3600 # Node ID 0571cf863026bfd41f46503e3b29e1e09076ba8f # Parent 2ae70581dafd914d47e6d3b35b5e3dd69511a58c Hack into the component the decoding of the chosen audio file, this needs refactoring and actually thinking about. Now, how to get the AudioBuffer to the waveform component? diff -r 2ae70581dafd -r 0571cf863026 src/app/audio-file-open/audio-file-open.component.html --- a/src/app/audio-file-open/audio-file-open.component.html Thu Oct 27 13:40:48 2016 +0100 +++ b/src/app/audio-file-open/audio-file-open.component.html Thu Oct 27 14:44:37 2016 +0100 @@ -1,4 +1,4 @@ - + diff -r 2ae70581dafd -r 0571cf863026 src/app/audio-file-open/audio-file-open.component.ts --- a/src/app/audio-file-open/audio-file-open.component.ts Thu Oct 27 13:40:48 2016 +0100 +++ b/src/app/audio-file-open/audio-file-open.component.ts Thu Oct 27 14:44:37 2016 +0100 @@ -1,5 +1,14 @@ import {Component, OnInit, ViewChild, ElementRef} from '@angular/core'; +interface AudioContextConstructor { + new(): AudioContext +} + +interface WindowAudioContext { + AudioContext?: AudioContextConstructor; + webkitAudioContext?: AudioContextConstructor +} + @Component({ selector: 'app-audio-file-open', templateUrl: './audio-file-open.component.html', @@ -9,14 +18,27 @@ @ViewChild('open') open: ElementRef; - constructor() { } + private audioContext: AudioContext; + + constructor() { + // TODO make a service which provides the AudioContext? + const factory: WindowAudioContext = (window as WindowAudioContext); + this.audioContext = new (factory.AudioContext || factory.webkitAudioContext)(); + } ngOnInit() { } - openAudio(files: FileList) { - console.log(files); - console.log("open"); + decodeAudio(files: FileList) { + if (files.length > 0) { + const reader: FileReader = new FileReader(); + reader.onload = (event: any) => { + this.audioContext.decodeAudioData(event.target.result, buffer => { + console.log(buffer); + }); + }; + reader.readAsArrayBuffer(files[0]); + } } openAudioDialog() {