Autoplay Cross-Browser

Asked

Viewed 37 times

1

How do I give autoplay to all (or almost all) mobile and desktop browsers?

<audio controls autoplay>
<source src="horse.ogg" type="audio/ogg">
<source src="horse.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>

Apparently this code removed from here, doesn’t work. Does anyone know any way to do this using pure Javascript or HTML or any other technology?

I know a lot of people will say this is bad practice, but it’s for a web-radio.

  • 1

    I think for mobile phone there is no possibility to do autoplay because of certain policies, at least if it is used in Chrome

  • Really, I don’t think this has a solution...

1 answer

0

It shouldn’t work because you don’t have the file in your directory. horse.mp3 and horse.ogg should not exist, makes direct link:

src="https://www.w3schools.com/tags/horse.ogg"

and

src="https://www.w3schools.com/tags/horse.mp3"

Or download to your working directory of the files horse.mp3 and horse.ogg.

  • The file exists, and when I press the button the music plays, the problem is autoplay, if it only works on the PC is good enough for me.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.