1

I have below code in JS to play audio

playThis = Audio + '/Audios/Orchestral/Organic_cloudcity.mp3'

    playAudio() {
        let audio = new Audio();
        audio.src = this.playThis;
        audio.load();
        audio.play();
    }

connectedcallback() {

        this.playAudio();
}

this doesn't work on chrome browser because of its auto play policy can anyone suggest if is there any work around to auto play this in chrome browser?

even this trailhead module adding sound effects in lwc doesn't work in chrome.

1 Answer 1

1

Auto play is a browser feature. If the autoplay is off, there is unlikely you will be able to do anything. This is a user setting and triumph over whatever code you will write.

These changes have been around in Chrome since 2017

Autoplay with sound is allowed if:

  • User has interacted with the domain (click, tap, etc.).

  • On desktop, the user's Media Engagement Index threshold has been crossed, meaning the user has previously played video with sound.

  • The user has added the site to their home screen on mobile or installed the PWA on desktop.

https://developers.google.com/web/updates/2017/09/autoplay-policy-changes

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .