ohmu
ohmu

Reputation: 19780

Allow Audio to Play on Page Load

I'm maintaining a legacy ASP/VBScript application for some warehouse scanners. They run Android 7 with Chrome 64. I can configure Chrome however I want so I'm not constrained like a normal website would be. Due to the nature of this web application, playing a sound on page load would improve usability (when the submitted action fails). Is there any way to allow an audio file to play on page load?

I can play sounds easily after a user interaction. However, I've tried multiple methods to play a sound on page load without success:

Upvotes: 2

Views: 2512

Answers (1)

Altin Mullaidrizi
Altin Mullaidrizi

Reputation: 314

Both Chrome and Firefox, have dropped support for the autoplay attribute for both audio and video unless it's a video with the sound muted.

You can read more on that here: Autoplay Policy

However, recently I found a workaround using the Howler.js library, and it seems to work quite well in just these lines of code:

let timer, sound;
sound = new Howl({
    src: ['<?= get_theme_file_uri() ?>/images/spotAudio.mp3']
});
sound.play();

You can download the library and read the docs here: https://howlerjs.com/

Upvotes: 0

Related Questions