Unlock the sound when scene start

Good afternoon , looking at the other topics from last year on how to unlock the sound, as of today is there any option to unlock the sound without using an event? and have it unlock automatically when the scene starts?

cc @docEdub, but I think it’s a requirement from the browser that sounds can only be started from a user interaction.

@ancherly you can use the howler.js library to play your sound without user interaction.

Here are some examples:
howler.js/examples at master · goldfire/howler.js (github.com)

The spatial audio example is so cool. :slight_smile:

Howler’s examples also play out when the user interacts with a click on the scene. (at least with google chrome during my test)

Yes, you’re right Dad72, you have to grant permission for autoplay media.

GPT3’s comment:

Autoplay is often restricted in web browsers, including Microsoft Edge, for security and user experience reasons. However, there are some ways to enable autoplay for specific websites or media types in Microsoft Edge.

Here’s how you can activate autoplay in Microsoft Edge:

  1. Open Microsoft Edge and click the three dots (…) in the top-right corner of the window.
  2. Click on “Settings” from the dropdown menu.
  3. Scroll down and click on “Cookies and site permissions”.
  4. Click on “Media autoplay”.
  5. Choose “Allow” to enable autoplay for all websites or “Limit” to block autoplay for websites that may have disruptive media content.
  6. If you choose “Limit”, you can further customize the autoplay settings by selecting “Block” or “Limit” from the dropdown menu next to each media type, such as video or audio.
  7. Additionally, you can add specific websites to the “Allow” or “Block” list by clicking on “Manage permissions” and adding the website URL.

Please note that enabling autoplay can potentially decrease the overall user experience and consume unnecessary bandwidth. It is recommended to use autoplay sparingly and only for relevant and valuable media content.


“Zulassen” = german “allow” (autoplay audio and media on websites)

By the way this is the simplest code snippet to play a sound with howler:

let hwl = new Howl({ src: ["sounds/sound.wav"] });
hwl.play();

Is it possible to set this option programmatically for a browser?

GPT3:
It is not possible to programmatically enable or disable autoplay in Microsoft Edge or any other web browser due to security reasons. This is because autoplay settings are considered part of the user’s privacy and browsing preferences, and therefore, can only be changed by the user manually through the browser settings.

However, there are some ways to prompt the user to change their autoplay settings by displaying a message or a popup that informs them about the media content and requests their permission to play it. For example, you can use the navigator.mediaDevices.getUserMedia() method to ask the user for permission to use their microphone or camera and play an audio or video file as a response.

Here’s an example code snippet that demonstrates how to request user permission for autoplay:

javascriptCopy code

var video = document.createElement('video');
video.muted = true;
video.autoplay = true;
video.src = 'myvideo.mp4';

var promise = video.play();

if (promise !== undefined) {
  promise.then(function() {
    // Autoplay started successfully
  }).catch(function(error) {
    // Autoplay was prevented
    // Show a message or a popup that informs the user about the media content and requests their permission to play it
  });
}

This code creates a new video element, sets its src property to the URL of the video file, and sets its autoplay and muted properties to true. The play() method is then called on the video element, which returns a promise that resolves if the autoplay started successfully or rejects if the autoplay was prevented. If the autoplay was prevented, you can show a message or a popup that informs the user about the media content and requests their permission to play it.

@Dad72 , @CodingCrusader thank you for answering and providing so much information, I will try a little with what you have said and I will comment here my experience, thank you very much for your time. :heartpulse:

Correct. This is enforced by browsers and is the only way to be sure the audio context is unlocked. To be absolutely clear: audio libraries like howler.js can not work around this limitation.

The most transparent way to handle this is to have an intro screen on your web page with an “Enter” or “Start” button (or something similar) that’s required to be pressed to kick things off.

1 Like