Home > The Newbie Zone > Questions and Answers

Need a code snippet to play audio on autoplay on landing page (10)


11-07-2015 01:54 PM #1 sawrubh (Member)
Need a code snippet to play audio on autoplay on landing page

I want to play an alert sound when my landing page loads. I have used the audio tag with autoplay option enabled however it doesn't work in Chrome on Android. Can someone tell me a code snippet which works?


11-13-2015 08:06 PM #2 sawrubh (Member)

Bumping since I still haven't found a code snippet yet.


11-13-2015 09:37 PM #3 anurag007 (Member)

Can you write here the code that you used ?


11-13-2015 09:44 PM #4 whtang (Member)

here is the code snippet i use on my landing pages. Add those before </body> tag

<audio autoplay="autoplay" preload="">
<source src="youraudiofile.oga" type="audio/ogg">
</audio>

change your audio type accordingly

hope its helps


11-13-2015 10:42 PM #5 sawrubh (Member)

Code:
<audio autoplay="autoplay" preload="">
    <source src="alert.mp3" type="audio/mpeg">
    <source src="alert.ogg" type="audio/ogg">
</audio>
is what I have used and it doesn't work.

@whtang, I tried adding this right before the ending body tag but it still didn't work.


11-14-2015 06:29 AM #6 erikgyepes (Moderator)

It doesn't work because autoplay is not allowed in mobile browsers.
It must be hooked to some user action like "click" to play the sound.

https://www.aerserv.com/why-does-vid...ices-not-work/


11-16-2015 03:18 AM #7 bobliu (Member)

Yeah due to excessive data w/o users consent. It's usually tied to an event unless they select otherwise.

Do you still want code? Perhaps attached event to next step button.


12-27-2016 01:40 PM #8 banana123 (Member)

It doesn't work because autoplay is not allowed in mobile browsers.
It must be hooked to some user action like "click" to play the sound.
Thought I'd bump this thread instead of starting a new one.

My plan was to add a small audio ding when my landing page loads on a user's phone. Is this not possible?


12-28-2016 04:04 AM #9 erikgyepes (Moderator)

This is what you need guys: https://howlerjs.com/


12-28-2016 01:11 PM #10 banana123 (Member)

Quote Originally Posted by whtang View Post
here is the code snippet i use on my landing pages. Add those before </body> tag

<audio autoplay="autoplay" preload="">
<source src="youraudiofile.oga" type="audio/ogg">
</audio>

change your audio type accordingly

hope its helps
So this isn't an option anymore, we can't get audio to autoplay in mobile browsers?

Thanks for the link Erik, but it's way over my head


Home > The Newbie Zone > Questions and Answers