Quantcast
Channel: Internet Explorer Web Development forum
Viewing all articles
Browse latest Browse all 3527

Microsoft edge, javascript Audio Play() function not working properly

$
0
0

I have a page with many audio buttons, and it doesn't work in Edge. The play function is similar to the following:

       <button id="btn1" >xxx</button>
        <button id="btn2">yyy</button>
< audio id="player"></audio>
    <script>
    var audio = document.getElementById('player');
document.getElementById('btn1').addEventListener("click", function(){
audio.src = "tiger.mp3";
audio.play();
});

document.getElementById('btn2').addEventListener("click", function(){
audio.src = "toy.mp3";
audio.play();
});
    </script>

The .play(); function doesn't react to clicks most of the time. Only one out of six buttons actually start playing the sound, and with a 3 seconds delay. The audio file is on my computer, so there's no download time. It works well in Chrome. I am using an updated surface pro 4.

I have found out, that if I open the same page 3 times (in 3 tabs) in Edge browser, the 3rd instance will work well.


Viewing all articles
Browse latest Browse all 3527

Trending Articles