Spaces:
Sleeping
Sleeping
File size: 15,594 Bytes
e4c7604 | 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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
import React, { useState, useRef, useEffect } from 'react';
import { GeneratedVideo } from '../types';
import { GeminiService } from '../geminiService';
const VideoPlayer: React.FC<{ url: string }> = ({ url }) => {
const videoRef = useRef<HTMLVideoElement>(null);
const [isPlaying, setIsPlaying] = useState(false);
const [progress, setProgress] = useState(0);
const [volume, setVolume] = useState(1);
const [isMuted, setIsMuted] = useState(false);
const [duration, setDuration] = useState(0);
const [currentTime, setCurrentTime] = useState(0);
const [showControls, setShowControls] = useState(true);
const controlsTimeoutRef = useRef<number | null>(null);
const togglePlay = () => {
if (videoRef.current) {
if (isPlaying) {
videoRef.current.pause();
} else {
videoRef.current.play();
}
setIsPlaying(!isPlaying);
}
};
const handleTimeUpdate = () => {
if (videoRef.current) {
const current = videoRef.current.currentTime;
const total = videoRef.current.duration;
setCurrentTime(current);
setProgress((current / total) * 100);
}
};
const handleSeek = (e: React.ChangeEvent<HTMLInputElement>) => {
const seekTime = (parseFloat(e.target.value) / 100) * duration;
if (videoRef.current) {
videoRef.current.currentTime = seekTime;
setProgress(parseFloat(e.target.value));
}
};
const handleVolumeChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const val = parseFloat(e.target.value);
setVolume(val);
if (videoRef.current) {
videoRef.current.volume = val;
setIsMuted(val === 0);
}
};
const toggleMute = () => {
if (videoRef.current) {
const newMuteState = !isMuted;
setIsMuted(newMuteState);
videoRef.current.muted = newMuteState;
if (!newMuteState && volume === 0) {
setVolume(0.5);
videoRef.current.volume = 0.5;
}
}
};
const formatTime = (time: number) => {
const minutes = Math.floor(time / 60);
const seconds = Math.floor(time % 60);
return `${minutes}:${seconds < 10 ? '0' : ''}${seconds}`;
};
const handleMouseMove = () => {
setShowControls(true);
if (controlsTimeoutRef.current) window.clearTimeout(controlsTimeoutRef.current);
controlsTimeoutRef.current = window.setTimeout(() => {
if (isPlaying) setShowControls(false);
}, 3000);
};
useEffect(() => {
const video = videoRef.current;
if (video) {
const onLoadedMetadata = () => setDuration(video.duration);
video.addEventListener('loadedmetadata', onLoadedMetadata);
return () => video.removeEventListener('loadedmetadata', onLoadedMetadata);
}
}, []);
return (
<div
className="relative group bg-black rounded-3xl overflow-hidden border border-slate-800 shadow-2xl aspect-video"
onMouseMove={handleMouseMove}
onMouseLeave={() => isPlaying && setShowControls(false)}
>
<video
ref={videoRef}
src={url}
className="w-full h-full object-cover cursor-pointer"
onTimeUpdate={handleTimeUpdate}
onClick={togglePlay}
playsInline
/>
{/* Big Play Overlay */}
{!isPlaying && (
<div
onClick={togglePlay}
className="absolute inset-0 flex items-center justify-center bg-black/20 backdrop-blur-[2px] cursor-pointer transition-all hover:bg-black/40"
>
<div className="w-20 h-20 bg-indigo-600 rounded-full flex items-center justify-center shadow-3xl shadow-indigo-600/40 animate-in zoom-in duration-300">
<svg className="w-8 h-8 text-white ml-1" fill="currentColor" viewBox="0 0 24 24"><path d="M8 5v14l11-7z" /></svg>
</div>
</div>
)}
{/* Custom Controls Bar */}
<div className={`absolute bottom-0 left-0 right-0 p-6 bg-gradient-to-t from-black via-black/80 to-transparent transition-opacity duration-500 ${showControls ? 'opacity-100' : 'opacity-0 pointer-events-none'}`}>
{/* Progress Bar */}
<div className="relative w-full h-1.5 bg-slate-800 rounded-full mb-6 group/progress cursor-pointer">
<div
className="absolute top-0 left-0 h-full bg-indigo-500 rounded-full z-10"
style={{ width: `${progress}%` }}
/>
<input
type="range"
min="0"
max="100"
step="0.1"
value={progress}
onChange={handleSeek}
className="absolute inset-0 w-full h-full opacity-0 cursor-pointer z-20"
/>
</div>
<div className="flex items-center justify-between gap-6">
<div className="flex items-center gap-6">
<button onClick={togglePlay} className="text-white hover:text-indigo-400 transition-colors">
{isPlaying ? (
<svg className="w-6 h-6" fill="currentColor" viewBox="0 0 24 24"><path d="M6 19h4V5H6v14zm8-14v14h4V5h-4z" /></svg>
) : (
<svg className="w-6 h-6" fill="currentColor" viewBox="0 0 24 24"><path d="M8 5v14l11-7z" /></svg>
)}
</button>
<div className="flex items-center gap-3 group/volume">
<button onClick={toggleMute} className="text-slate-400 hover:text-white transition-colors">
{isMuted || volume === 0 ? (
<svg className="w-5 h-5" fill="currentColor" viewBox="0 0 24 24"><path d="M16.5 12c0-1.77-1.02-3.29-2.5-4.03v8.05c1.48-.73 2.5-2.25 2.5-4.02zM14 3.23v2.06c2.89.86 5 3.54 5 6.71s-2.11 5.85-5 6.71v2.06c4.01-.91 7-4.49 7-8.77s-2.99-7.86-7-8.77zM4.27 3L3 4.27 7.73 9H3v6h4l5 5v-6.73l4.25 4.25c-.67.52-1.42.93-2.25 1.18v2.06c1.38-.31 2.63-.95 3.69-1.81L19.73 21 21 19.73 4.27 3z" /></svg>
) : (
<svg className="w-5 h-5" fill="currentColor" viewBox="0 0 24 24"><path d="M3 9v6h4l5 5V4L7 9H3zm13.5 3c0-1.77-1.02-3.29-2.5-4.03v8.05c1.48-.73 2.5-2.25 2.5-4.02zM14 3.23v2.06c2.89.86 5 3.54 5 6.71s-2.11 5.85-5 6.71v2.06c4.01-.91 7-4.49 7-8.77s-2.99-7.86-7-8.77z" /></svg>
)}
</button>
<input
type="range"
min="0"
max="1"
step="0.01"
value={isMuted ? 0 : volume}
onChange={handleVolumeChange}
className="w-20 h-1 bg-slate-800 rounded-full appearance-none cursor-pointer accent-white"
/>
</div>
<div className="text-[10px] font-black text-slate-500 uppercase tracking-widest">
<span className="text-white">{formatTime(currentTime)}</span> / {formatTime(duration)}
</div>
</div>
<div className="flex items-center gap-4">
<span className="text-[8px] font-black text-indigo-400 bg-indigo-500/10 px-3 py-1 rounded-full uppercase tracking-widest border border-indigo-500/20">720p HD</span>
<button className="text-slate-400 hover:text-white transition-colors">
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5l-5-5m5 5v-4m0 4h-4" /></svg>
</button>
</div>
</div>
</div>
</div>
);
};
const VideoView: React.FC = () => {
const [videos, setVideos] = useState<GeneratedVideo[]>([]);
const [prompt, setPrompt] = useState('');
const [isGenerating, setIsGenerating] = useState(false);
const generate = async () => {
if (!prompt || isGenerating) return;
setIsGenerating(true);
try {
const url = await GeminiService.generateVideo(prompt);
setVideos(prev => [{ id: Date.now().toString(), url, prompt, status: 'completed', timestamp: Date.now() }, ...prev]);
setPrompt('');
} catch (err) {
console.error(err);
alert("Video generation failed. Ensure you have a paid API key selected.");
} finally {
setIsGenerating(false);
}
};
const handleShare = (vid: GeneratedVideo) => {
const text = `I just generated this cinematic AI video: "${vid.prompt}" on OmniNexus!`;
const url = `https://wa.me/?text=${encodeURIComponent(text)}`;
window.open(url, '_blank');
};
return (
<div className="max-w-6xl mx-auto px-6 py-12">
<div className="mb-16 text-center">
<div className="inline-block px-4 py-1.5 rounded-full bg-indigo-500/10 border border-indigo-500/20 text-indigo-400 text-[10px] font-black uppercase tracking-[0.2em] mb-6">
Veo 3.1 Fast Node
</div>
<h2 className="text-5xl font-black mb-4 tracking-tight text-white">Video Lab.</h2>
<p className="text-slate-500 text-lg max-w-2xl mx-auto mb-12">Harness next-gen cinematic AI to generate high-fidelity video assets.</p>
<div className="max-w-2xl mx-auto space-y-6">
<div className="bg-[#0a0f1e] border border-slate-800 p-2 rounded-[32px] focus-within:border-indigo-500/50 transition-all shadow-3xl">
<textarea
value={prompt}
onChange={(e) => setPrompt(e.target.value)}
placeholder="Describe a cinematic scene (e.g. A neon-lit street in Mumbai with flying rickshaws)..."
rows={3}
className="w-full bg-transparent border-none focus:ring-0 px-6 py-4 resize-none text-slate-200"
/>
</div>
<button
onClick={generate}
disabled={isGenerating || !prompt}
className="w-full premium-gradient px-8 py-6 rounded-[32px] text-white font-black uppercase tracking-widest text-lg disabled:opacity-50 shadow-2xl shadow-indigo-600/20 hover:scale-[1.02] active:scale-95 transition-all"
>
{isGenerating ? 'Synthesizing Frames (1-3 mins)...' : 'Launch Generation'}
</button>
</div>
</div>
<div className="grid grid-cols-1 gap-12">
{isGenerating && (
<div className="aspect-video bg-[#0a0f1e] rounded-[40px] flex flex-col items-center justify-center border border-slate-800 p-12 text-center shadow-3xl">
<div className="relative w-24 h-24 mb-10">
<div className="absolute inset-0 border-4 border-indigo-500/10 rounded-full" />
<div className="absolute inset-0 border-4 border-indigo-500 border-t-transparent rounded-full animate-spin" />
<div className="absolute inset-4 border-4 border-indigo-400/20 border-b-transparent rounded-full animate-spin-reverse" />
</div>
<h3 className="text-2xl font-black text-white mb-3 uppercase tracking-tighter">Crafting Cinematic Assets</h3>
<p className="text-slate-500 text-sm font-medium max-w-sm">Our neural network is computing lighting, physics, and motion for your specific prompt.</p>
</div>
)}
{videos.map((vid) => (
<div key={vid.id} className="bg-[#0a0f1e] rounded-[48px] p-8 border border-slate-800/60 shadow-3xl flex flex-col md:flex-row gap-8 animate-in slide-in-from-bottom duration-700">
<div className="w-full md:w-3/5">
<VideoPlayer url={vid.url} />
</div>
<div className="w-full md:w-2/5 flex flex-col justify-between py-4">
<div>
<div className="flex items-center gap-3 mb-6">
<span className="w-2 h-2 rounded-full bg-indigo-500"></span>
<span className="text-[10px] font-black text-slate-500 uppercase tracking-widest">Asset Metadata</span>
</div>
<h4 className="text-2xl font-black text-white leading-tight mb-4 italic">"{vid.prompt}"</h4>
<div className="space-y-3">
<div className="flex justify-between text-[10px] font-black uppercase tracking-widest py-2 border-b border-white/5">
<span className="text-slate-700">Resolution</span>
<span className="text-slate-300">1280 x 720</span>
</div>
<div className="flex justify-between text-[10px] font-black uppercase tracking-widest py-2 border-b border-white/5">
<span className="text-slate-700">Engine</span>
<span className="text-slate-300">Veo 3.1 Preview</span>
</div>
<div className="flex justify-between text-[10px] font-black uppercase tracking-widest py-2 border-b border-white/5">
<span className="text-slate-700">Timestamp</span>
<span className="text-slate-300">{new Date(vid.timestamp).toLocaleTimeString()}</span>
</div>
</div>
</div>
<div className="flex flex-col gap-3">
<div className="flex gap-4">
<a
href={vid.url}
download
className="flex-1 bg-white text-black py-4 rounded-2xl text-[10px] font-black uppercase tracking-widest text-center hover:bg-slate-200 transition-colors"
>
Download
</a>
<button
onClick={() => handleShare(vid)}
className="flex-1 bg-emerald-600 text-white py-4 rounded-2xl text-[10px] font-black uppercase tracking-widest hover:bg-emerald-500 transition-colors flex items-center justify-center gap-2"
>
<svg className="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path d="M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0012.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 00-3.48-8.413z"/></svg>
WhatsApp Share
</button>
</div>
</div>
</div>
</div>
))}
</div>
<style>{`
@keyframes spin-reverse {
from { transform: rotate(0deg); }
to { transform: rotate(-360deg); }
}
.animate-spin-reverse {
animation: spin-reverse 2s linear infinite;
}
input[type='range']::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 12px;
height: 12px;
background: white;
border-radius: 50%;
cursor: pointer;
box-shadow: 0 0 10px rgba(99, 102, 241, 0.5);
}
`}</style>
</div>
);
};
export default VideoView;
|