-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTest.jsx
34 lines (27 loc) · 855 Bytes
/
Test.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { useEffect, useRef, useState } from 'react'
function VideoPlayer ({src, isPlaying}) {
const ref = useRef(null);
useEffect(() => {
if(isPlaying) {
ref.current.play();
} else {
ref.current.pause();
}
}, [isPlaying]);
return <video src={src} ref={ref} loop playsInline/>
}
const Test = () => {
const [isPlaying, setIsPlaying] = useState(false);
return (
<main className='w-screen h-screen flex flex-col gap-10 justify-center items-center'>
<button onClick={()=> setIsPlaying(!isPlaying)}
className='bg-red-500 rounded-xl p-4 text-3xl'>
{isPlaying ? "pause" : "play" }
</button>
<VideoPlayer
isPlaying={isPlaying}
src="https://www.dofactory.com/media/movie.mp4"/>
</main>
)
}
export default Test