2017-06-06 23:19:12 +02:00
|
|
|
import React from "react";
|
|
|
|
import lbry from "lbry";
|
2017-06-07 07:36:12 +02:00
|
|
|
import VideoPlayer from "./internal/player";
|
|
|
|
import VideoPlayButton from "./internal/play-button";
|
2017-06-07 06:12:45 +02:00
|
|
|
import LoadingScreen from "./internal/loading-screen";
|
2017-05-02 15:58:35 +02:00
|
|
|
|
2017-06-08 06:42:19 +02:00
|
|
|
class Video extends React.PureComponent {
|
2017-04-23 11:56:50 +02:00
|
|
|
constructor(props) {
|
2017-06-06 23:19:12 +02:00
|
|
|
super(props);
|
|
|
|
this.state = { isPlaying: false };
|
2017-04-23 11:56:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
startPlaying() {
|
|
|
|
this.setState({
|
2017-06-06 23:19:12 +02:00
|
|
|
isPlaying: true,
|
|
|
|
});
|
2017-04-23 11:56:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
metadata,
|
|
|
|
isLoading,
|
|
|
|
isDownloading,
|
|
|
|
fileInfo,
|
2017-05-31 19:36:38 +02:00
|
|
|
contentType,
|
2017-06-06 23:19:12 +02:00
|
|
|
} = this.props;
|
|
|
|
const { isPlaying = false } = this.state;
|
2017-04-23 11:56:50 +02:00
|
|
|
|
2017-06-06 23:19:12 +02:00
|
|
|
const isReadyToPlay = fileInfo && fileInfo.written_bytes > 0;
|
|
|
|
const mediaType = lbry.getMediaType(
|
|
|
|
contentType,
|
|
|
|
fileInfo && fileInfo.file_name
|
|
|
|
);
|
2017-05-15 18:34:33 +02:00
|
|
|
|
2017-06-06 23:19:12 +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."
|
|
|
|
);
|
2017-05-28 15:38:36 +02:00
|
|
|
} else if (isLoading) {
|
2017-06-06 23:19:12 +02:00
|
|
|
loadStatusMessage = __(
|
|
|
|
"Requesting stream... it may sit here for like 15-20 seconds in a really awkward way... we're working on it"
|
|
|
|
);
|
2017-04-23 11:56:50 +02:00
|
|
|
} else if (isDownloading) {
|
2017-06-06 23:19:12 +02:00
|
|
|
loadStatusMessage = __("Downloading stream... not long left now!");
|
2017-04-23 11:56:50 +02:00
|
|
|
}
|
|
|
|
|
2017-06-06 23:19:12 +02:00
|
|
|
let klassName = "";
|
|
|
|
if (isLoading || isDownloading) klassName += "video-embedded video";
|
2017-05-31 19:36:38 +02:00
|
|
|
if (mediaType === "video") {
|
2017-06-06 23:19:12 +02:00
|
|
|
klassName += "video-embedded video";
|
|
|
|
klassName += isPlaying ? " video--active" : " video--hidden";
|
2017-06-02 19:54:11 +02:00
|
|
|
} else if (mediaType === "application") {
|
2017-06-06 23:19:12 +02:00
|
|
|
klassName += "video-embedded";
|
2017-05-31 19:36:38 +02:00
|
|
|
} else {
|
2017-06-06 23:19:12 +02:00
|
|
|
if (!isPlaying) klassName += "video-embedded";
|
2017-05-31 19:36:38 +02:00
|
|
|
}
|
2017-06-06 23:19:12 +02:00
|
|
|
const poster = metadata.thumbnail;
|
2017-05-31 19:36:38 +02:00
|
|
|
|
2017-04-23 11:56:50 +02:00
|
|
|
return (
|
2017-06-06 23:19:12 +02:00
|
|
|
<div className={klassName}>
|
2017-06-07 06:12:45 +02:00
|
|
|
{isPlaying &&
|
|
|
|
(!isReadyToPlay
|
|
|
|
? <LoadingScreen status={loadStatusMessage} />
|
2017-06-06 23:19:12 +02:00
|
|
|
: <VideoPlayer
|
|
|
|
filename={fileInfo.file_name}
|
|
|
|
poster={poster}
|
|
|
|
downloadPath={fileInfo.download_path}
|
|
|
|
mediaType={mediaType}
|
2017-06-10 19:07:28 +02:00
|
|
|
downloadCompleted={fileInfo.completed}
|
2017-06-07 06:12:45 +02:00
|
|
|
/>)}
|
|
|
|
{!isPlaying &&
|
|
|
|
<div
|
|
|
|
className="video__cover"
|
|
|
|
style={{ backgroundImage: 'url("' + metadata.thumbnail + '")' }}
|
|
|
|
>
|
|
|
|
<VideoPlayButton
|
|
|
|
startPlaying={this.startPlaying.bind(this)}
|
|
|
|
{...this.props}
|
|
|
|
mediaType={mediaType}
|
|
|
|
/>
|
|
|
|
</div>}
|
2017-05-31 19:36:38 +02:00
|
|
|
</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;
|