Jump to content

I have autoplay on web view, but what code do i need to apply this to mobile?

Recommended Posts

Hey guys, this code I have found/put together from what i know, but when previewing in mobile, my hidden audio block doesn't autoplay. Can anyone help please?


<script>
window.addEventListener('DOMContentLoaded', function() { //wait for document load
    var audio = document.querySelector('.sqs-audio-embed'); //select the audio block
        var checkOnLoad = function() {
            if (window.pageYOffset > 200) {
            } else {
                audio.play();
            }
          {audio.loop = true;}
        };
        if (audio) {
            var url = audio.getAttribute('data-url'); //get the audio src
            Y.one(audio).ancestor('.sqs-block-audio').setStyle('display','none');
            audio = new Audio(url);
            window.addEventListener('load', checkOnLoad); //listen for window load and toggle audio state
            checkOnLoad();
        }
})
</script>

Edited by IanHost
added tags
Link to comment
  • Replies 5
  • Views 529
  • Created
  • Last Reply

Top Posters In This Topic

  • 2 weeks later...
  • 1 year later...
  • 3 months later...
On 3/10/2023 at 11:03 AM, sanfranciscosasha said:

Tuan and Ian, i'm having the same problem, and using the same code as Ian. 

 

My audio autoplays in chrome while i am in my editing mode, but no in safari or mobile. 

 

Here is the website, would appreciate some help on how you were able to solve it. 

https://bell-now.squarespace.com

password ---- >     demo

 

You can consider this approach, I use another code

 

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

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.