Jump to content

How to autoplay mp3 song on home page?

Recommended Posts

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

  • 1 month later...

@Soredadux

One way to do this is to add a code block and enter the following code.

<audio controls autoplay>

  <source src="[enter your MP3 file url here]" type="audio/mpeg">
  
  Your browser does not support the audio element.
  
  </audio>

Replace the [enter your MP3 file URL here] with the URL for your MP3 file.

If you have different versions of the audio files for playability on a wider range of platforms you can add source tags

 <source src="" type="audio/ogg">

See HTML <audio> Tag < https://www.w3docs.com/learn-html/html-audio-tag.html > for more info.

Let us know how it goes.

Edited by creedon

Find my contributions useful? Please like, upvote, mark my answer as best , and see my profile. Thanks for your support!

Link to comment
2 hours ago, creedon said:

One way to do this is to add a code block and enter the following code.


<audio controls autoplay>

  <source src="[enter your MP3 file url here]" type="audio/mpeg">
  
  Your browser does not support the audio element.
  
  </audio>

Replace the [enter your MP3 file URL here] with the URL for your MP3 file.

If you have different versions of the audio files for playability on a wider range of platforms you can add source tags

 <source src="" type="audio/ogg">

See HTML <audio> Tag < https://www.w3docs.com/learn-html/html-audio-tag.html > for more info.

Let us know how it goes.

Hi! It was the first thing I've tried, but doesn't work on smartphones and I really don't know how to style it. Right now I have this code:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
    //var buttons = document.getElementsByClassName("play-button");
      console.log("1");
    //setTimeout(function(){
      $(".sqs-block-code").click(function() {
      $(".play").click();
      $(".sqs-block-code").off();
    });
    //},3000);
  
    //setTimeout(function(){ $(".play").click(); }, 3000);
});
</script>

The things is that works only if you make "click" on the page (anywhere).

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.