Skip to content

Conversation

@W-Floyd
Copy link

@W-Floyd W-Floyd commented Dec 15, 2025

Fixes #159

@W-Floyd W-Floyd marked this pull request as draft December 15, 2025 22:45
@W-Floyd W-Floyd changed the title feat: Add option to automatically play on load, or when page url ends in `#autoplay feat: Add option to automatically play on load, or when page url ends in #autoplay Dec 15, 2025
@W-Floyd
Copy link
Author

W-Floyd commented Dec 16, 2025

Ah, I'd added a log during testing but forgot to remove the import. @badaix you want a debug log on autoplay?

@badaix
Copy link
Member

badaix commented Dec 16, 2025

Ah, I'd added a log during testing but forgot to remove the import. @badaix you want a debug log on autoplay?

yes, why not, I think a debug log won't hurt

@W-Floyd W-Floyd marked this pull request as ready for review December 16, 2025 16:19
@badaix
Copy link
Member

badaix commented Dec 18, 2025

I tried it and I'm running into the problem that the browser does not start playing audio, but throws this error:

(index):1 Uncaught (in promise) NotAllowedError: play() failed because the user didn't interact with the document first. https://goo.gl/xX8pDD

@W-Floyd
Copy link
Author

W-Floyd commented Dec 18, 2025

If the browser has allowed the site to autoplay, it works. Eg, Firefox setting:
image
image

That is to say, the browser must either allow sites to autoplay, or the user will need to manually set it to be allowed. Maybe we could do a check and notify the user (if nothing else, in the console) if autoplay not being allowed?

@badaix
Copy link
Member

badaix commented Dec 19, 2025

Yes, I think we need a check and notify the user if autoplay is not working. Snapweb is already using "Alert Snackbars" if the server can't be reached, such a snackbar could be used to inform the user that autoplay is not allowed.

@W-Floyd
Copy link
Author

W-Floyd commented Dec 26, 2025

See https://caniuse.com/mdn-api_navigator_getautoplaypolicy. I'm using this check, but falling back to trying directly if it's unknown. Currently only Firefox supports reading this directly, so we rely on fallback in all other cases.

Safari:
image

Firefox:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Play by default option

2 participants