Squall Leonhart
Squall Leonhart

Reputation: 439

Playing base64 audio file doesn't work on newest version of Chrome (46.0.2490.86 m)

I have a problem with playing base64 audio file on newest Chrome 46.0.2490.86 m

This audio file can play only 1 times. It doesn't play on second times.

We need to refresh browser to relay again. This file played well on previous version of Chrome (can replay many times without refreshing browser).

This is my code:

window.playAudio1 = function () {
    var audio = document.getElementById("audio");
    audio.src = "<base64 mp3 audio>";
    audio.play();
}

window.playAudio2 = function () {
    var audio = document.getElementById("audio");
    audio.src = "<base64 mp3 audio>";
    audio.play();
}

JSFiddle

Upvotes: 1

Views: 1133

Answers (1)

Brooky
Brooky

Reputation: 148

I encountered the same problem recently.

The only way i could get it to work was to include some random information in the base64 info.

e.g.

        
        function beep()
        {
            try
            {
                var snd = new Audio("data:audio/wav;rnd=" + getRandom(1,100000) + ";base64,<<raw base64 data>>");
                snd.load();
                snd.currentTime = 0;
                snd.play();
            }
            catch(e)
            {
                alert(e);
            }
        }

        function getRandom(min, max) {
            return Math.random() * (max - min) + min;
        }

I also tried adding in the .load() and the .currentTime = 0, but to be honest, i don't think they are required for the fix, didn't try without though.

Enjoy!

Upvotes: 1

Related Questions