Sulla tua domanda, sembra che jQuery non lo supporti ancora. Prima di utilizzarlo come suggerito di seguito, è consigliabile verificare se la funzionalità è disponibile.
Con XHTMLRequest, puoi ingannare il tuo server e ricevere una stringa binaria che rappresenta i byte che vuoi dal server. Funziona perfettamente.
var xhr = new XMLHttpRequest();
xhr.open('GET', '/your/audio/file.wav', true);
// Here is the hack
xhr.overrideMimeType('text/plain; charset=x-user-defined');
xhr.onreadystatechange = function(event) {
if (this.readyState == 4 && this.status == 200) {
var binaryString = this.responseText;
for (var i = 0, len = binaryString.length; i < len; ++i) {
var c = binaryString.charCodeAt(i);
var byte = c & 0xff; //it gives you the byte at i
//Do your cool stuff...
}
}
};
xhr.send();
Funziona, è comune ... ma ... è ancora un hack.
Con XHTML Richiesta livello 2, è possibile specificare responseType come 'arraybuffer' e ricevere effettivamente ArrayBuffer. È molto più bello Il problema è verificare se il tuo browser supporta questa funzionalità.
var xhr = new XMLHttpRequest();
xhr.open('GET', '/your/audio/file.wav', true);
xhr.responseType = 'arraybuffer';
xhr.onload = function(e) {
if (this.status == 200) {
//Do your stuff here
}
};
xhr.send();
Spero di aver aiutato.
fonte
2013-05-22 17:07:20
Si dovrebbe provare e vedere. – Musa