-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AutoPlay for HTML5 <video>: detect "Unhandled Promise Rejection: " #272
Comments
Hello, We were working on it! For just the rejection of play part, I see two things that would work:
We already have a warning event which communicates about various errors when they are not fatal (they do not stop playback). We could add a specific Then, the task of managing that particular case will be on the UI side, having something like: player.addEventListener("warning", function handleWarnings(error) {
if (error.code === "AUTOPLAY_NOT_ALLOWED") {
displayAutoPlayNotAllowedPopUp();
}
});
This solution can already work today. The rx-player usually goes through several states when starting a content in autoPlay mode, in this order:
Based on that, you can manage the autoPlay feature yourself just by:
Here we would have in the UI: player.addEventListener("playerStateChange", function handleStateChanges(state) {
if (state === "LOADED") {
// try to auto-play
var promise = document.querySelector('video').play();
if (promise !== undefined) {
promise.catch(error => {
if (error.name === "NotAllowedError") {
displayAutoPlayNotAllowedPopUp();
}
});
}
}
}); The first point is being implemented right now, the second one has the advantage of already being available. Then again, we seem to have another issue for Safari: From the very few tests we could do on it (it is kind of hard for us to do for dumb reasons -> we mostly work on computers dual booting linux + windows), it seems that this browser also blocks the We will continue our tests, but if this is true, it means that it will be difficult for us to send the In that case, we will have to rely on another method to switch to the EDIT: added precision about what a "fatal" error means |
Thank you for the update.
I had to sligthly alter MUTE/UNMUTE functions
In
The NOTE: In my code base P.S. Gladly would help with testing, my dev setup is OS and got iOS test devices. |
We added a In that case, the Warnings/errors and how to handle them is documented here. Basically, you will have to do something allong the line of: player.addEventListener("warning", (warning) => {
if (warning.code === "MEDIA_ERR_BLOCKED_AUTOPLAY") {
// show UI to start the stream manually
}
}); |
Current state of affairs
With desktop Safari, Chrome and others starting to block playback for HTML5
<audio>
and<video>
"without user action" similar to iOS Safari and mobile Chrome, with some special rules and exceptions for major sites like YouTube et al.The Webkit announcement. Important note: users can disable auto-play entirely, even for silent videos.
https://webkit.org/blog/7734/auto-play-policy-changes-for-macos/
The Chromium project is following the same policy from version M66 Stable.
https://sites.google.com/a/chromium.org/dev/audio-video/autoplay
Possible solution
On iOS Safari 11 the media element's method
.play()
returns following:Unhandled Promise Rejection: NotAllowedError (DOM Exception 35): The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission.
Anyway, I get to catch this while using rx-player ?
The recommended way by Apple is:
The text was updated successfully, but these errors were encountered: