0

audio autoplay working in Mozilla, Microsoft edge and old google chrome as well but not in new google chrome. they have blocked the autoplay. is there any way to make it audio autoplay in google chrome?

the answer given on this: How to make audio autoplay on chrome is no longer working.

Edric
  • 24,639
  • 13
  • 81
  • 91
Tiya Mehta
  • 11
  • 1
  • 1
  • 1

3 Answers3

1

Try This The best fix I could get was adding this code just after the

var x = document.getElementById("myAudio"); 


  x.play(); 
<audio id="myAudio" controls>

  <source src="https://file-examples.com/wp-content/uploads/2017/11/file_example_MP3_700KB.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>
1

There is a smart hack that will autoplay with sound once get required microphone permission from users:

    navigator.mediaDevices.getUserMedia({ audio: true }).then(function (stream) {
        
       var x = document.getElementById("myAudio"); 
       x.play();
    
        // stop microphone stream acquired by getUserMedia
        stream.getTracks().forEach(function (track) { track.stop(); });
    });

It works because as long as you are capturing then you are allowed to play and then stop the microphone stream when your audio starts playing. Otherwise, you have to instruct users to allow Sound Permission using site settings themselves which is technically weird.

0

Here is a way to get this to happen.... Using a redirect will take you to a 'new' page - just make the 'new' page as you want. In this case I'm redirecting to the sound and it plays immediately.

   <head>
   <meta http-equiv="refresh" content="0; URL=http://xyz/myrecord.mp3" />
   </head>
   <body></body>

Its that easy

Winston
  • 38
  • 6