You cannot reduce the delay, since you have no control over the browser code and the size of the buffering. The HTML5 specification does not apply any restrictions, so I see no reason why this has improved.
However, you can implement a solution with the webaudio API (which is pretty simple), where you process the streams yourself.
If you can split your MP3 fragment in a fixed size (so that each size of MP3 fragments is known in advance, or at least during reception), you can broadcast in 20 lines of code. The block size will be your delay.
The key is to use AudioContext :: decodeAudioData.
// Fix up prefixing window.AudioContext = window.AudioContext || window.webkitAudioContext; var context = new AudioContext(); var offset = 0; var byteOffset = 0; var minDecodeSize = 16384; // This is your chunk size var request = new XMLHttpRequest(); request.onprogress = function(evt) { if (request.response) { var size = request.response.length - byteOffset; if (size < minDecodeSize) return; // In Chrome, XHR stream mode gives text, not ArrayBuffer. // If in Firefox, you can get an ArrayBuffer as is var buf; if (request.response instanceof ArrayBuffer) buf = request.response; else { ab = new ArrayBuffer(size); buf = new Uint8Array(ab); for (var i = 0; i < size; i++) buf[i] = request.response.charCodeAt(i + byteOffset) & 0xff; } byteOffset = request.response.length; context.decodeAudioData(ab, function(buffer) { playSound(buffer); }, onError); } }; request.open('GET', url, true); request.responseType = expectedType; // 'stream' in chrome, 'moz-chunked-arraybuffer' in firefox, 'ms-stream' in IE request.overrideMimeType('text/plain; charset=x-user-defined'); request.send(null); function playSound(buffer) { var source = context.createBufferSource(); // creates a sound source source.buffer = buffer; // tell the source which sound to play source.connect(context.destination); // connect the source to the context destination (the speakers) source.start(offset); // play the source now // note: on older systems, may have to use deprecated noteOn(time); offset += buffer.duration; }
source share