3
    function getAudio(aUrl) {
    var deferred = $.Deferred();
    // ajax is not capable of arraybuffer
    var xhr = new XMLHttpRequest();
    xhr.responseType = 'arraybuffer';
    xhr.open('GET', aUrl, true);

    // request succeeded
    xhr.onreadystatechange = function() {
        if (
            (xhr.readyState === 4) && 
            (xhr.status === 200) && 
            (xhr.status !== 404)
            ) {
            audioCtx.decodeAudioData(xhr.response, function(buffer) {
                buf = buffer;
                return deferred.resolve(true);
            });
        } 
    };
    xhr.onerror = function() {
        return deferred.resolve(false);
    };
    xhr.send();
    return deferred.promise();
}

My app has a function to send a XMLHttpRequest whose responseType is 'arraybuffer'. There is no error when used on Chrome, Safari, however Firefox gives me an error 'InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable'.

Many tutorials seem to have the pretty similar code. How could it be solved? One note is the argument 'aUrl' is not a local path. ex) "https://api.soundcloud.com/tracks/121818867/stream?client_id=8f474de4d1dedd5a6a4f4cbb60f4e6b8"

Yuma Yanagisawa
  • 235
  • 1
  • 4
  • 17
  • 3
    solved.[link](http://ja.stackoverflow.com/questions/2706/xhr-responsetype-arraybuffer-%E3%81%8C-firefox%E3%81%A7%E5%8B%95%E3%81%8B%E3%81%AA%E3%81%84) – Yuma Yanagisawa Dec 27 '14 at 17:11
  • 1
    You can answer your own question and earn more points. Thanks for this! – Niloct Feb 09 '15 at 00:40
  • 2
    Here's english language [solution](http://stackoverflow.com/questions/13216903/get-binary-data-with-xmlhttprequest-in-a-firefox-extension/13219346#comment45743285_13219346). Basically, `xhr.open()` must be placed before `xhr.responseType` in code - this affects currently only Firefox; Chrome or Opera works fine. – spaffy Feb 25 '15 at 20:10

0 Answers0