I've looked at all the similar questions having to do with FileReader and readAsArrayBuffer() but haven't had any luck.
I'm trying to use the Web Audio API to read in a local mp3 file and process it with FileReader in order to use it for some music visualization.
This is what I have currently:
var file = "../../audio/magic_coldplay.mp3";
var fileReader = new FileReader();
fileReader.onload = function (e) {
var fileResult = e.target.result;
visualizer.start(fileResult);
};
fileReader.onerror = function (e) {
debugger
};
fileReader.readAsArrayBuffer(file);
I'm getting the error: "Failed to execute 'readAsArrayBuffer' on 'FileReader': parameter 1 is not of type 'Blob'."
So I guess file isn't a Blob. The examples I've seen online have the user uploading their own mp3 file. How can I make this work with a local mp3?
thanks for any pointers you may have!
filehere is a string, far from a File or Blob... If this string represents a valid URI pointing to the file, then you can dofetch(file).then(r=>r.blob()).then(blob=>fileReader.readAsArrayBuffer(blob))