jeudi 21 septembre 2017

FileReader readAsArrayBuffer() with a local mp3 file

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!




Aucun commentaire:

Enregistrer un commentaire