test with promise.race

This commit is contained in:
Sean Yesmunt 2020-04-28 13:25:13 -04:00
parent 49128322d5
commit 04ee4afdc2
2 changed files with 26 additions and 13 deletions

View file

@ -118,18 +118,25 @@ function VideoViewer(props: Props) {
const shouldPlay = !embedded || autoplayIfEmbedded; const shouldPlay = !embedded || autoplayIfEmbedded;
// https://blog.videojs.com/autoplay-best-practices-with-video-js/#Programmatic-Autoplay-and-Success-Failure-Detection // https://blog.videojs.com/autoplay-best-practices-with-video-js/#Programmatic-Autoplay-and-Success-Failure-Detection
if (shouldPlay) { if (shouldPlay) {
const promise = player.play(); const playPromise = player.play();
if (promise !== undefined) { const timeoutPromise = new Promise((resolve, reject) => {
promise setTimeout(() => reject('test'), 1000);
.then(function() { });
// Autoplay started
}) Promise.race([playPromise, timeoutPromise]).catch(error => {
.catch(function(error) { if (error === 'test') {
// The player promise hung
// This is probably in firefox
// Try playing again, it works?
player.play();
} else {
// Autoplay was actually blocked by the browser.
// Reset everything so the user sees the thumbnail/play button and can start it on their own
setIsLoading(false); setIsLoading(false);
setIsPlaying(false); setIsPlaying(false);
setPlayingUri(null);
});
} }
console.log('error', error);
});
} }
setIsLoading(shouldPlay); // if we are here outside of an embed, we're playing setIsLoading(shouldPlay); // if we are here outside of an embed, we're playing
@ -164,7 +171,7 @@ function VideoViewer(props: Props) {
{isEndededEmbed && <FileViewerEmbeddedEnded uri={uri} />} {isEndededEmbed && <FileViewerEmbeddedEnded uri={uri} />}
{embedded && !isEndededEmbed && <FileViewerEmbeddedTitle uri={uri} />} {embedded && !isEndededEmbed && <FileViewerEmbeddedTitle uri={uri} />}
{/* disable this loading behavior because it breaks when player.play() promise hangs */} {/* disable this loading behavior because it breaks when player.play() promise hangs */}
{false && isLoading && <LoadingScreen status={__('Loading')} />} {isLoading && <LoadingScreen status={__('Loading')} />}
<VideoJs <VideoJs
source={source} source={source}
isAudio={isAudio} isAudio={isAudio}

View file

@ -315,6 +315,12 @@
display: flex; display: flex;
} }
} }
// Hide video controls on safari to prevent displaying two sets of controls
// Apple has their own controls for all devices
video::-webkit-media-controls-panel-container {
display: none !important;
}
} }
.file-viewer--ended-embed .vjs-big-play-button { .file-viewer--ended-embed .vjs-big-play-button {