Create src/pages/Watch.jsx
Browse files- src/pages/Watch.jsx +44 -0
src/pages/Watch.jsx
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { useParams, useNavigate } from 'react-router-dom';
|
| 2 |
+
import { useEffect, useState, useRef } from 'react';
|
| 3 |
+
import { fetchAnichinData } from '../config/firebase';
|
| 4 |
+
import Plyr from 'plyr';
|
| 5 |
+
import 'plyr/dist/plyr.css';
|
| 6 |
+
|
| 7 |
+
export default function Watch() {
|
| 8 |
+
const { id } = useParams();
|
| 9 |
+
const navigate = useNavigate();
|
| 10 |
+
const videoRef = useRef(null);
|
| 11 |
+
const [anime, setAnime] = useState(null);
|
| 12 |
+
|
| 13 |
+
useEffect(() => {
|
| 14 |
+
fetchAnichinData().then((data) => {
|
| 15 |
+
if (data && data[id]) setAnime(data[id]);
|
| 16 |
+
});
|
| 17 |
+
}, [id]);
|
| 18 |
+
|
| 19 |
+
useEffect(() => {
|
| 20 |
+
if (anime && videoRef.current) {
|
| 21 |
+
const player = new Plyr(videoRef.current, {
|
| 22 |
+
controls: ['play-large', 'play', 'progress', 'current-time', 'volume', 'fullscreen'],
|
| 23 |
+
theme: '#dc2626'
|
| 24 |
+
});
|
| 25 |
+
return () => player.destroy();
|
| 26 |
+
}
|
| 27 |
+
}, [anime]);
|
| 28 |
+
|
| 29 |
+
if (!anime) return <div className="p-10 text-white">Loading Player...</div>;
|
| 30 |
+
|
| 31 |
+
return (
|
| 32 |
+
<div className="min-h-screen bg-black px-4 py-8">
|
| 33 |
+
<button onClick={() => navigate('/')} className="mb-6 text-red-500 font-bold hover:text-white">← Back to Home</button>
|
| 34 |
+
<div className="max-w-5xl mx-auto">
|
| 35 |
+
<video ref={videoRef} className="plyr-react plyr" data-poster={anime.poster_url}>
|
| 36 |
+
{/* Asumsi format data URL video di database: anime.video_url */}
|
| 37 |
+
<source src={anime.video_url} type="video/mp4" />
|
| 38 |
+
</video>
|
| 39 |
+
<h2 className="text-3xl font-black mt-6">{anime.title}</h2>
|
| 40 |
+
<p className="text-gray-400 mt-2">{anime.synopsis}</p>
|
| 41 |
+
</div>
|
| 42 |
+
</div>
|
| 43 |
+
);
|
| 44 |
+
}
|