Skip to main content
whiskeywolf
Participant
November 23, 2022
Answered

Audio won't autoplay on website?

  • November 23, 2022
  • 1 reply
  • 1034 views

[Link removed by moderator as per forum guidelines.]

 

I'm using this script. I have the player hidden on purpose and the audio file is in the root of the site in the public.html folder. For some reason it is not playing?

 

<audio autoplay id="volumeset">
<source src="wolfhowl.mp3" type="audio/mpeg">
</audio>
<script>
var audio = document.getElementById("volumeset");
audio.volume = 0.1;
</script>

This topic has been closed for replies.
Correct answer Nancy OShea

GOOD!  That's how it should work.

 

Web devices and browsers don't support autoplay because it's obnoxious & rude: 

  • For people who work in close proximity to other employees. 
  • For parents with a sleeping baby nearby.
  • For me when my favorite podcast is interrupted with a cacophony of unwanted noise from an inconsiderate site owner.  😠

 

Remove autoplay.  And DO NOT set volume.  Give users controls with which to PLAY media and adjust volume as they see fit.

 

Replace everything you have now with this.  It's all you need:

 

<audio controls="controls" >
<source src="wolfhowl.mp3" type="audio/mp3">
</audio>

 

1 reply

Nancy OShea
Community Expert
Nancy OSheaCommunity ExpertCorrect answer
Community Expert
November 23, 2022

GOOD!  That's how it should work.

 

Web devices and browsers don't support autoplay because it's obnoxious & rude: 

  • For people who work in close proximity to other employees. 
  • For parents with a sleeping baby nearby.
  • For me when my favorite podcast is interrupted with a cacophony of unwanted noise from an inconsiderate site owner.  😠

 

Remove autoplay.  And DO NOT set volume.  Give users controls with which to PLAY media and adjust volume as they see fit.

 

Replace everything you have now with this.  It's all you need:

 

<audio controls="controls" >
<source src="wolfhowl.mp3" type="audio/mp3">
</audio>

 

Nancy O'Shea— Product User & Community Expert
whiskeywolf
Participant
November 23, 2022

Thank you. I do NOT want controls. I just want a short audio file of a wolf howl played softly in the background when the page loads. It is not some long loud file or anything like that. Is it possible? I followed the tutorials from this website and his works but mine doesnt? Not sure what I'm doing wrong?

https://www.tutorialbrain.com/html_tutorial/html5_audio/ 

Nancy OShea
Community Expert
Community Expert
November 23, 2022

That autoplay doesn't work for me either.  Nothing does because my browser blocks autoplay by default and it's that way for the majority of users.

 

If you don't believe me, this is what MDN says about autoplay.

https://developer.mozilla.org/docs/Web/Media/Autoplay_guide

 

 

 

 

Nancy O'Shea— Product User & Community Expert