Web Audio API delay for local files

Web Audio API delay for local files

BY 27 Aug 2013 Web Application Development

Hi,

I’m using Web Audio API with this code:

var Player = function () {
	this.audioContext = new webkitAudioContext();
}

Player.prototype.play = function (url) {
	var request = new XMLHttpRequest();
	request.open("GET", url, true);
	request.responseType = "arraybuffer";
	var audioContext = this.audioContext;
	request.onload = function () {
		var soundSource = audioContext.createBufferSource();
		audioContext.decodeAudioData(request.response, function(buffer) {
			soundSource.buffer = buffer;
		}, null);
		soundSource.connect(audioContext.destination);
		soundSource.noteOn(0);
	};
	request.send();
}

But I have a long delay before the playback of local files on Samsung RD-PQ with

var player = new Player();
player.play('file:///path-to-file.mp3');

How can I avoid it?

Written by