Skip to content
Snippets Groups Projects
Commit cf7ed287 authored by Karishma Chadha's avatar Karishma Chadha
Browse files

Fix issue with sound upload button not always working, and correctly cache...

Fix issue with sound upload button not always working, and correctly cache sound type if given an mp3.
parent 17f5ed7a
Branches
Tags
No related merge requests found
......@@ -140,7 +140,7 @@ class ActionMenu extends React.Component {
fileInput, accept: fileAccept, fileChange, fileInputRef}) => {
const isComingSoon = !handleClick;
const hasFileInput = fileInput;
const tooltipId = `tooltip-${Math.random()}`;
const tooltipId = title;
return (
<div key={tooltipId}>
<button
......
......@@ -107,14 +107,19 @@ class SoundTab extends React.Component {
handleSoundUpload (e) {
const thisFileInput = e.target;
let thisFile = null;
const reader = new FileReader();
reader.onload = () => {
// Reset the file input value now that we have everything we need
// so that the user can upload the same sound multiple times if
// they choose
thisFileInput.value = null;
// Cache the sound in storage
const soundBuffer = reader.result;
const storage = this.props.vm.runtime.storage;
// TODO only accepting .wav files right now,
// but later will have to do something sensible with other types of sounds
const soundFormat = storage.DataFormat.WAV;
const fileType = thisFile.type; // what file type does the browser think this is
const soundFormat = fileType === 'audio/mp3' ? storage.DataFormat.MP3 : storage.DataFormat.WAV;
const md5 = storage.builtinHelper.cache(
storage.AssetType.Sound,
soundFormat,
......@@ -133,13 +138,12 @@ class SoundTab extends React.Component {
});
};
if (thisFileInput.files) {
reader.readAsArrayBuffer(thisFileInput.files[0]);
thisFileInput.value = null;
thisFile = thisFileInput.files[0];
reader.readAsArrayBuffer(thisFile);
}
}
setFileInput (input) {
console.log('setting file input!');
if (input && !this.fileInput) this.fileInput = input;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment