0

I am trying to make audio auto-play (without mute) on my website index page for Halloween effect. Tried all tricks given in the internet and Stack. Everything fails. But I found in W3Schools, tried on its page and it's working with auto-play. I am curious how it is working only on that website.

I used the same code:

<audio controls autoplay>
  <source src="horse.ogg" type="audio/ogg">
  <source src="https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>

But not working for me in my site!

There source to check autoplay : here

another one here with js

How is it working for them and not for me?

Behrad Hajmiri
  • 230
  • 2
  • 7
bestway
  • 11
  • 3
  • 2
    It doesn't autoplay for them neither. If you just click on that link to open it in a new tab, it wont initially play a sound. – Ivar Oct 27 '22 at 07:29
  • Are you sure abt the audio file paths ? provide some more screenshots and proper code. – Nishanth Oct 27 '22 at 07:30
  • If you read the docs about [Autoplay availability](https://developer.mozilla.org/en-US/docs/Web/Media/Autoplay_guide#autoplay_availability) you'll see that you need to comply to at least one rule the make use of autoplay. – Reyno Oct 27 '22 at 07:34
  • When it is not visited in new tab its autoplaying in that W3school webiste @Ivar Please copy link and try it. Its playing on there website. When i use same code its not working on mine. – bestway Oct 27 '22 at 09:25
  • Yes @Nishanth am sure about audio file path. Because, its playing without issue when adding manual play button – bestway Oct 27 '22 at 09:26
  • @Reyno Yes i already tried many solutions from Internet like that you shared and same as that. Not working brother – bestway Oct 27 '22 at 09:27
  • No @Ivar They mentioned there in answer u shared as its not possible in chrome. But, that W3school autoplaying same audio in Chrome. That mean there is a way right ! If they can why can't I is what my question – bestway Oct 27 '22 at 09:28
  • No. The only ways are mentioned in the answer to the post I linked. It needs a user gesture, the domain needs to be high-ranked (like YouTube) or possibly it needs to be invoked from within the same origin. The last one might be the case for W3Schools. Like I mentioned in my first comment, if you open the link here from Stack Overflow, _it does not_ autoplay. It's too annoying for users, so it's not possible to just automatically play audio anymore. – Ivar Oct 27 '22 at 09:33
  • Alternatively for W3Schools, you have engaged enough with playing audio before, putting it above the threshold to allow autoplay [as described here](https://developer.chrome.com/blog/autoplay/#media-engagement-index). But that only applies to your browser. It doesn't auto play for me or other users that haven't engaged with media on W3Schools. – Ivar Oct 27 '22 at 09:47

1 Answers1

-1

You Cann't do it.

Please see https://developer.chrome.com/blog/autoplay/

and to play it only when the browser get a user gesture .

diqye
  • 54
  • 2
  • I don't want every user to change there browser settings brother. I need tweak from website side itself – bestway Oct 27 '22 at 09:36