lbry-desktop/src/renderer/component/video/view.jsx

141 lines
3.6 KiB
React
Raw Normal View History

2018-03-26 23:32:43 +02:00
// @flow
import React from 'react';
import lbry from 'lbry';
2018-03-26 23:32:43 +02:00
import classnames from 'classnames';
import VideoPlayer from './internal/player';
import VideoPlayButton from './internal/play-button';
import LoadingScreen from './internal/loading-screen';
2018-03-26 23:32:43 +02:00
type Props = {
cancelPlay: () => void,
fileInfo: {
outpoint: string,
file_name: string,
written_bytes: number,
download_path: string,
completed: boolean,
},
metadata: ?{
nsfw: boolean,
thumbnail: string,
},
isLoading: boolean,
isDownloading: boolean,
playingUri: ?string,
contentType: string,
changeVolume: number => void,
volume: number,
claim: {},
uri: string,
doPlay: () => void,
doPause: () => void,
savePosition: (string, number) => void,
mediaPaused: boolean,
mediaPosition: ?number,
className: ?string,
obscureNsfw: boolean,
play: string => void,
};
2017-04-23 11:56:50 +02:00
2018-03-26 23:32:43 +02:00
class Video extends React.PureComponent<Props> {
2017-09-18 04:13:05 +02:00
componentWillUnmount() {
this.props.cancelPlay();
}
2018-03-26 23:32:43 +02:00
isMediaSame(nextProps: Props) {
return (
this.props.fileInfo &&
nextProps.fileInfo &&
this.props.fileInfo.outpoint === nextProps.fileInfo.outpoint
);
}
2017-04-23 11:56:50 +02:00
render() {
const {
metadata,
isLoading,
isDownloading,
playingUri,
2017-04-23 11:56:50 +02:00
fileInfo,
contentType,
changeVolume,
volume,
claim,
uri,
2017-12-21 00:38:11 +01:00
doPlay,
doPause,
savePosition,
2017-12-21 00:38:11 +01:00
mediaPaused,
mediaPosition,
2018-03-26 23:32:43 +02:00
className,
obscureNsfw,
play,
2017-06-06 23:19:12 +02:00
} = this.props;
2017-04-23 11:56:50 +02:00
const isPlaying = playingUri === uri;
2017-06-06 23:19:12 +02:00
const isReadyToPlay = fileInfo && fileInfo.written_bytes > 0;
2018-03-26 23:32:43 +02:00
const shouldObscureNsfw = obscureNsfw && metadata && metadata.nsfw;
const mediaType = lbry.getMediaType(contentType, fileInfo && fileInfo.file_name);
2017-05-15 18:34:33 +02:00
let loadStatusMessage = '';
2017-04-23 11:56:50 +02:00
2017-06-06 23:19:12 +02:00
if (fileInfo && fileInfo.completed && !fileInfo.written_bytes) {
loadStatusMessage = __(
"It looks like you deleted or moved this file. We're rebuilding it now. It will only take a few seconds."
);
} else if (isLoading) {
loadStatusMessage = __('Requesting stream...');
2017-04-23 11:56:50 +02:00
} else if (isDownloading) {
loadStatusMessage = __('Downloading stream... not long left now!');
2017-04-23 11:56:50 +02:00
}
2018-03-26 23:32:43 +02:00
const poster = metadata && metadata.thumbnail;
2017-04-23 11:56:50 +02:00
return (
2018-03-26 23:32:43 +02:00
<div className={classnames('video', {}, className)}>
{isPlaying && (
<div className="content__view">
{!isReadyToPlay ? (
<LoadingScreen status={loadStatusMessage} />
) : (
<VideoPlayer
filename={fileInfo.file_name}
poster={poster}
downloadPath={fileInfo.download_path}
mediaType={mediaType}
contentType={contentType}
downloadCompleted={fileInfo.completed}
changeVolume={changeVolume}
volume={volume}
doPlay={doPlay}
doPause={doPause}
savePosition={savePosition}
claim={claim}
uri={uri}
paused={mediaPaused}
position={mediaPosition}
/>
)}
</div>
)}
{!isPlaying && (
<div
className={classnames('content__cover', { 'card__media--nsfw': shouldObscureNsfw })}
style={!shouldObscureNsfw && poster ? { backgroundImage: `url("${poster}")` } : {}}
>
<VideoPlayButton
play={play}
fileInfo={fileInfo}
2018-01-05 20:27:58 +01:00
uri={uri}
2018-03-26 23:32:43 +02:00
isLoading={isLoading}
mediaType={mediaType}
/>
</div>
)}
</div>
2017-06-06 23:19:12 +02:00
);
2017-04-23 11:56:50 +02:00
}
}
2017-06-06 06:21:55 +02:00
export default Video;