Mercurial > hg > ugly-duckling
diff src/app/app.component.ts @ 134:976087b98e72
Allow for opening Blobs directly.
| author | Lucas Thompson <dev@lucas.im> |
|---|---|
| date | Mon, 20 Mar 2017 13:26:23 +0000 |
| parents | c02c76b94148 |
| children | ac57ddba8ba9 |
line wrap: on
line diff
--- 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);
