0

I have searched so much but I can't find an alternative! Here is my code:

<audio autoplay>
     <source src="music.mp3" type="audio/mpeg">
</audio>
Asher Memon
  • 62
  • 1
  • 11

2 Answers2

1

As you may have noticed, web browsers are moving towards stricter autoplay policies in order to improve the user experience, minimize incentives to install ad blockers, and reduce data consumption on expensive and/or constrained networks. These changes are intended to give greater control of playback to users and to benefit publishers with legitimate use cases.

Chrome's autoplay policies are simple:

Muted autoplay is always allowed. Autoplay with sound is allowed if: User has interacted with the domain (click, tap, etc.). On desktop, the user's Media Engagement Index threshold has been crossed, meaning the user has previously played video with sound. The user has added the site to their home screen on mobile or installed the PWA on desktop. Top frames can delegate autoplay permission to their iframes to allow autoplay with sound.

https://developers.google.com/web/updates/2017/09/autoplay-policy-changes

allow="autoplay"

is also a possibility. Other than that you might want to experiment with the tag

<audio controls></audio>
Newstack
  • 53
  • 7
0

Since there is only one source tag, you can put the source in the audio tag's src attribute.

<audio autoplay src="https://www.w3schools.com/tags/horse.mp3"></audio>

JSFiddle - https://jsfiddle.net/8850s/L5uzb34y/

Note that this may not work in the StackSnippet above.

shreyasm-dev
  • 2,711
  • 5
  • 16
  • 34