Standard HTML audio elements won't play
opened this issue · comments
Deleted user commented
The following snippet does not work if using standard HTML audio (not using web audio and not using marmalade):-
var sound = new b5.Sound("explosion", "Explode.mp3", true );
sound.play();
Here is the fix:-
//Fixed version of sound play function
b5.Sound.prototype.play = function()
{
if (b5.app.use_web_audio)
{
if (this.buffer === null)
return null;
var context = b5.Sound.context;
var source = context.createBufferSource();
var gain = context.createGain();
source.buffer = this.buffer;
source.loop = this.loop;
source.connect(gain);
gain.connect(context.destination);
gain.gain.value = 1;
source.start(0);
if (this.auto_play)
this.snd = { source: source, gain: gain };
return { source: source, gain: gain };
}
var snd = null;
if (this.reuse)
snd = this.snd;
if (snd === null)
{
//fix
this.load();
snd = this.snd;
//fix
}
if (snd !== null) {
snd.play();
}
return snd;
};