Hopki,
Sorry for this late reply, but I have been doing a lot of testing around this issue.
Here is what I found out. But first, a few words about my plan:
- Yes, most browsers by default don't allow autoplay, and that's fine. I have no intention to somehow bypass
this setting.
- I have some panos where it would make sense to autoplay a background sound. These panos are set with a loop value of 0;
- For these panos I use the JS API to start playing immediately.
- Now, if the browser requires user intervention, i.e. a click by the user, the JS engine will - correctly - throw an error,
so need to catch it before it causes the entire script to fail.
- There is a way to deal with this situation, it goes like this:
Code: Select all
window.addEventListener('unhandledrejection', function(event) {
console.log(event.promise); // [object Promise] - the promise that generated the error
console.log(event.reason); // Error: Whoops! - the unhandled error object
// and now do something ...
});
- This code works fine. My script recovers from the error and continue doing its job.
Now it gets interesting:
If a user clicks
anywhere on the page, not just on the sound player play button,
the
background sound starts playing. As far as I am concerned this is not supposed to happen
and it's a serious issue, as it screws up the entire sound logic.
Best,
Franco