|
1 |
| -import React, {useContext, useEffect, useRef, useState} from 'react'; |
| 1 | +import React, {useContext, useRef, useState} from 'react'; |
| 2 | +import ReactPlayer from 'react-player/file'; |
2 | 3 | import {FinderSettings} from 'finder/FinderSettings';
|
3 |
| -import FileDetails from './FileDetails'; |
| 4 | +import {FileDetails} from 'finder/FileDetails'; |
| 5 | +import PauseIcon from 'icons/pause.svg'; |
| 6 | +import PlayIcon from 'icons/play.svg'; |
| 7 | +import CameraIcon from 'icons/camera.svg'; |
4 | 8 |
|
5 | 9 |
|
6 | 10 | export default function Video(props) {
|
| 11 | + const sampleFields = { |
| 12 | + posterFrame: document.getElementById('id_poster_frame') as HTMLInputElement, |
| 13 | + }; |
7 | 14 | const settings = useContext(FinderSettings);
|
| 15 | + const style = { |
| 16 | + width: '960px', |
| 17 | + maxWidth: '100%', |
| 18 | + height: 'auto', |
| 19 | + }; |
| 20 | + const videoRef = useRef(null); |
| 21 | + const [isPlaying, setIsPlaying] = useState(false); |
8 | 22 |
|
| 23 | + const onReady = () => { |
| 24 | + } |
| 25 | + |
| 26 | + const onPlayPause = () => { |
| 27 | + const player = videoRef.current.getInternalPlayer(); |
| 28 | + if (isPlaying) { |
| 29 | + player.pause(); |
| 30 | + setIsPlaying(false); |
| 31 | + } else { |
| 32 | + player.play(); |
| 33 | + setIsPlaying(true); |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + const createPosterFrame = () => { |
| 38 | + const currentTime = videoRef.current.getCurrentTime(); |
| 39 | + sampleFields.posterFrame.value = currentTime; |
| 40 | + } |
| 41 | + |
| 42 | + const controlButtons = [(isPlaying ? |
| 43 | + <button onClick={onPlayPause}><PauseIcon/>{gettext("Pause")}</button> : |
| 44 | + <button onClick={onPlayPause}><PlayIcon/>{gettext("Play")}</button> |
| 45 | + ), |
| 46 | + <button onClick={createPosterFrame}><CameraIcon/>{gettext("Create Poster Frame")}</button> |
| 47 | + ]; |
9 | 48 | return (
|
10 |
| - <FileDetails> |
11 |
| - <video src={settings.download_url}></video> |
| 49 | + <FileDetails controlButtons={controlButtons} style={style}> |
| 50 | + <ReactPlayer |
| 51 | + url={settings.download_url} |
| 52 | + controls={true} |
| 53 | + controlsList="nofullscreen nodownload" |
| 54 | + disablePictureInPicture={true} |
| 55 | + onReady={onReady} |
| 56 | + onPlay={() => setIsPlaying(true)} |
| 57 | + onPause={() => setIsPlaying(false)} |
| 58 | + pip={false} |
| 59 | + ref={videoRef} |
| 60 | + width="100%" |
| 61 | + height="100%" |
| 62 | + /> |
12 | 63 | </FileDetails>
|
13 | 64 | );
|
14 | 65 | }
|
0 commit comments