Mute video when autoplay is blocked by browser policy #6087

Merged
infinite-persistence merged 1 commit from ip/mute.video.for.autoplay.policy into master 2021-05-19 17:56:54 +02:00
2 changed files with 7 additions and 0 deletions
Showing only changes of commit c3f46987cc - Show all commits

View file

@ -38,6 +38,7 @@ export type Player = {
controlBar: { controlBar: {
addChild: (string, any) => void, addChild: (string, any) => void,
}, },
autoplay: (any) => boolean,
}; };
type Props = { type Props = {

View file

@ -221,6 +221,12 @@ function VideoViewer(props: Props) {
); );
Promise.race([playPromise, timeoutPromise]).catch((error) => { Promise.race([playPromise, timeoutPromise]).catch((error) => {
if (typeof error === 'object' && error.name && error.name === 'NotAllowedError') {
if (player.autoplay() && !player.muted()) {
player.muted(true);
}
}
if (PLAY_TIMEOUT_ERROR) { if (PLAY_TIMEOUT_ERROR) {
const retryPlayPromise = player.play(); const retryPlayPromise = player.play();
Promise.race([retryPlayPromise, timeoutPromise]).catch((error) => { Promise.race([retryPlayPromise, timeoutPromise]).catch((error) => {