# HG changeset patch # User Lucas Thompson # Date 1490016383 0 # Node ID 976087b98e72afe2d1c452eab4591e054663e362 # Parent 4452f4b9f9a85294c3d5c6eeb3d9991b05e3f2de Allow for opening Blobs directly. diff -r 4452f4b9f9a8 -r 976087b98e72 src/app/app.component.ts --- a/src/app/app.component.ts Mon Mar 20 13:25:22 2017 +0000 +++ b/src/app/app.component.ts Mon Mar 20 13:26:23 2017 +0000 @@ -27,22 +27,27 @@ ); } - onFileOpened(file: File) { + onFileOpened(file: File | Blob) { this.canExtract = false; this.isProcessing = true; 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})) - ); + const url: string = file instanceof Blob ? URL.createObjectURL(file) : + URL.createObjectURL(new Blob([event.target.result], {type: mimeType})); + this.audioService.loadAudioFromUrl(url); // TODO use a rxjs/Subject instead? - this.audioService.decodeAudioData(event.target.result).then(audioBuffer => { + this.audioService.decodeAudioData(event.target.result) + .then(audioBuffer => { this.audioBuffer = audioBuffer; if (this.audioBuffer) { this.canExtract = true; this.isProcessing = false; } + }).catch(error => { + this.canExtract = false; + this.isProcessing = false; + console.warn(error); }); }; reader.readAsArrayBuffer(file);