2020-06-22 13:46:19 +00:00
|
|
|
import ReactPlayer from "react-player";
|
2020-09-26 12:59:33 +00:00
|
|
|
import React, { Ref } from "react";
|
|
|
|
|
import styled from "styled-components";
|
2021-03-13 14:24:45 +00:00
|
|
|
import { createMessage, ENTER_VIDEO_URL } from "constants/messages";
|
2020-09-26 12:59:33 +00:00
|
|
|
export interface VideoComponentProps {
|
|
|
|
|
url?: string;
|
|
|
|
|
autoplay?: boolean;
|
|
|
|
|
controls?: boolean;
|
|
|
|
|
onStart?: () => void;
|
|
|
|
|
onPlay?: () => void;
|
|
|
|
|
onPause?: () => void;
|
|
|
|
|
onEnded?: () => void;
|
|
|
|
|
onReady?: () => void;
|
|
|
|
|
onProgress?: () => void;
|
|
|
|
|
onSeek?: () => void;
|
|
|
|
|
onError?: () => void;
|
|
|
|
|
player?: Ref<ReactPlayer>;
|
|
|
|
|
}
|
2020-06-22 13:46:19 +00:00
|
|
|
|
2020-09-26 12:59:33 +00:00
|
|
|
const ErrorContainer = styled.div`
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 100%;
|
2020-06-22 13:46:19 +00:00
|
|
|
`;
|
|
|
|
|
|
2020-09-26 12:59:33 +00:00
|
|
|
const Error = styled.span``;
|
2020-06-22 13:46:19 +00:00
|
|
|
|
2020-09-26 12:59:33 +00:00
|
|
|
export default function VideoComponent(props: VideoComponentProps) {
|
|
|
|
|
const {
|
|
|
|
|
autoplay,
|
|
|
|
|
controls,
|
|
|
|
|
onEnded,
|
2021-05-13 08:35:39 +00:00
|
|
|
onError,
|
|
|
|
|
onPause,
|
|
|
|
|
onPlay,
|
2020-09-26 12:59:33 +00:00
|
|
|
onProgress,
|
2021-05-13 08:35:39 +00:00
|
|
|
onReady,
|
2020-09-26 12:59:33 +00:00
|
|
|
onSeek,
|
2021-05-13 08:35:39 +00:00
|
|
|
onStart,
|
2020-09-26 12:59:33 +00:00
|
|
|
player,
|
2021-05-13 08:35:39 +00:00
|
|
|
url,
|
2020-09-26 12:59:33 +00:00
|
|
|
} = props;
|
2021-04-28 10:28:39 +00:00
|
|
|
return url ? (
|
|
|
|
|
<ReactPlayer
|
|
|
|
|
controls={controls || true}
|
|
|
|
|
height="100%"
|
|
|
|
|
onEnded={onEnded}
|
|
|
|
|
onError={onError}
|
|
|
|
|
onPause={onPause}
|
|
|
|
|
onPlay={onPlay}
|
|
|
|
|
onProgress={onProgress}
|
|
|
|
|
onReady={onReady}
|
|
|
|
|
onSeek={onSeek}
|
|
|
|
|
onStart={onStart}
|
|
|
|
|
pip={false}
|
|
|
|
|
playing={autoplay}
|
|
|
|
|
ref={player}
|
|
|
|
|
url={url}
|
|
|
|
|
width="100%"
|
|
|
|
|
/>
|
|
|
|
|
) : (
|
|
|
|
|
<ErrorContainer>
|
|
|
|
|
<Error>{createMessage(ENTER_VIDEO_URL)}</Error>
|
|
|
|
|
</ErrorContainer>
|
2020-06-22 13:46:19 +00:00
|
|
|
);
|
2020-09-26 12:59:33 +00:00
|
|
|
}
|