I'm having trouble loading an audio file then putting it into readAsArrayBuffer. I don't want the user to choose a file, I just want it to load one locally like so:
let file = new File('../music/song.mp3');
let reader = new FileReader();
reader.onload = function(e) {
playSound(e.target.result);
}
reader.readAsArrayBuffer(file);
When I do the above, I get the following error:
Uncaught TypeError: Failed to construct 'File': 2 arguments required, but only 1 present.
So I try this:
let file = new File([''], '../music/song.mp3');
Which then produces this error:
Uncaught (in promise) DOMException: Unable to decode audio data
The size of what it loads is 0, which I believe is why it's producing this error.
Everything works fine when I let the user choose a file to load:
document.getElementById('open-file').onchange = function(evt) {
let file = evt.target.files[0];
Does anyone know how to fix this?