try twice when the first play fails from a timeout

This commit is contained in:
Sean Yesmunt 2020-04-29 10:36:43 -04:00
parent b61907ad22
commit c9f5813b81

View file

@ -120,13 +120,21 @@ function VideoViewer(props: Props) {
if (shouldPlay) {
const playPromise = player.play();
const timeoutPromise = new Promise((resolve, reject) => {
setTimeout(() => reject(PLAY_TIMEOUT_ERROR), 2500);
setTimeout(() => reject(PLAY_TIMEOUT_ERROR), 2000);
});
Promise.race([playPromise, timeoutPromise]).catch(error => {
if (PLAY_TIMEOUT_ERROR) {
const retryPlayPromise = player.play();
Promise.race([retryPlayPromise, timeoutPromise]).catch(error => {
setIsLoading(false);
setIsPlaying(false);
});
} else {
setIsLoading(false);
setIsPlaying(false);
}
});
}
setIsLoading(shouldPlay); // if we are here outside of an embed, we're playing