import React, { useEffect, useRef, useState } from 'react'; import styled from 'styled-components'; import KaraokePlayer from './components/KaraokePlayer'; import { toast, ToastContainer } from 'react-toastify'; import 'react-toastify/dist/ReactToastify.css'; const Root = styled.div` position: absolute; width: 100%; height: 100%; top: 0; left: 0; display: flex; flex-direction: column; align-items: center; background-color: #f5f5f5; `; const FileInputContainer = styled.div` margin-bottom: 20px; display: flex; justify-content: center; gap: 20px; padding: 10px; border-radius: 5px; background-color: #ffffff; box-shadow: 0 2px 4px rgba(0,0,0,0.1); `; const FileInput = styled.input` padding: 10px 15px; border-radius: 5px; border: 1px solid #ddd; cursor: pointer; display: none; &:hover, &:focus { background-color: #eaeaea; outline: none; } `; const FileInputLabel = styled.label` padding: 10px 15px; border-radius: 5px; border: 1px solid #ddd; cursor: pointer; &:hover, &:focus { background-color: #eaeaea; outline: none; } `; function App() { const [currentMillisecond, setCurrentMillisecond] = useState(0); const [lrcContent, setLrcContent] = useState(''); const [videoUrl, setVideoUrl] = useState(''); const [showFileInputs, setShowFileInputs] = useState(true); const videoRef = useRef(null); const [offset, setOffset] = useState('0'); const handleLrcFileChange = (event: React.ChangeEvent) => { const file = event.target.files?.[0]; if (file) { const reader = new FileReader(); reader.onload = (e) => { setLrcContent(e.target?.result as string); if (videoUrl) setShowFileInputs(false); }; reader.readAsText(file); toast.success("LRC file loaded successfully", { autoClose: 2000 }); } }; const handleVideoFileChange = (event: React.ChangeEvent) => { const file = event.target.files?.[0]; if (file) { const url = URL.createObjectURL(file); setVideoUrl(url); setShowFileInputs(true); toast.success("Video file loaded successfully", { autoClose: 2000 }); } }; useEffect(() => { const video = videoRef.current; if (!video) return; const syncLrcWithVideo = () => { console.log(offset); setCurrentMillisecond((video.currentTime * 1000) + parseInt(offset)); }; video.addEventListener('timeupdate', syncLrcWithVideo); return () => { video.removeEventListener('timeupdate', syncLrcWithVideo); }; }); return (
setShowFileInputs(true)} onMouseLeave={() => setShowFileInputs(false)}> {videoUrl ?
); } export default App;