From 2afbda719817a9b498529afb6a0a5aa4e2ff16e8 Mon Sep 17 00:00:00 2001 From: btzr-io Date: Wed, 4 Jul 2018 00:26:50 -0600 Subject: [PATCH] rework loadingScreen logic --- .../component/video/internal/player.jsx | 62 ++++++++++++++----- 1 file changed, 46 insertions(+), 16 deletions(-) diff --git a/src/renderer/component/video/internal/player.jsx b/src/renderer/component/video/internal/player.jsx index d470f4d52..39170b898 100644 --- a/src/renderer/component/video/internal/player.jsx +++ b/src/renderer/component/video/internal/player.jsx @@ -58,9 +58,9 @@ class VideoPlayer extends React.PureComponent { this.renderAudio(container, null, false); } // Render custom viewer: FileRender - if (this.fileType()) this.renderFile(); + else if (this.fileType()) this.renderFile(); // Render default viewer: render-media (video, audio, img, iframe) - else if (this.supportedType()) { + else { player.append( this.file(), container, @@ -214,30 +214,60 @@ class VideoPlayer extends React.PureComponent { container.appendChild(audio); } - render() { - const { mediaType, poster } = this.props; + showLoadingScreen(isFileType, isPlayableType) { const { hasMetadata, unplayable, unsupported, fileSource } = this.state; + + const loader = { + isLoading: false, + loadingStatus: null, + }; + + // Loading message const noFileMessage = 'Waiting for blob.'; const noMetadataMessage = 'Waiting for metadata.'; + + // Error message const unplayableMessage = "Sorry, looks like we can't play this file."; const unsupportedMessage = "Sorry, looks like we can't preview this file."; - const isLoadingFile = !fileSource && this.fileType(); - const isLoadingMetadata = this.playableType() && (!hasMetadata && !unplayable); - const isUnplayable = this.playableType() && unplayable; - const isUnsupported = !this.supportedType() && !this.playableType() && !this.fileType(); - const isFile = fileSource && this.fileType(); + + // Files + const isLoadingFile = !fileSource && isFileType; + const isUnsupported = !this.supportedType() && isPlayableType && !isFileType; + + // Media (audio, video) + const isUnplayable = isPlayableType && unplayable; + const isLoadingMetadata = isPlayableType && (!hasMetadata && !unplayable); + + // Show loading message + if (isLoadingFile || isLoadingMetadata) { + loader.loadingStatus = isFileType ? noFileMessage : noMetadataMessage; + loader.isLoading = true; + + // Show unsupported error message + } else if (isUnsupported || isUnplayable) { + loader.loadingStatus = isFileType ? unsupportedMessage : unplayableMessage; + } + + return loader; + } + + render() { + const { mediaType } = this.props; + const { fileSource } = this.state; + + const isFileType = this.fileType(); + const isFileReady = fileSource && isFileType; + const isPlayableType = this.playableType(); + const { isLoading, loadingStatus } = this.showLoadingScreen(isFileType, isPlayableType); + console.info(isLoading, loadingStatus); return ( - {isLoadingFile && } - {isLoadingMetadata && } - {isUnplayable && } - {unsupported || - (isUnsupported && )} - {isFile && } + {loadingStatus && } + {isFileReady && }
{ this.media = container; }}