'use client'; import React, { useRef, useEffect } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import { Edit3, Play, Pause } from 'lucide-react'; import { ProgressiveReveal, presets } from '@/components/ui/progressive-reveal'; import { GlassIconButton } from '@/components/ui/glass-icon-button'; interface MediaViewerProps { currentStep: string; currentSketchIndex: number; taskSketch: any[]; taskVideos: any[]; isVideoPlaying: boolean; isPlaying: boolean; showControls: boolean; isGeneratingSketch: boolean; isGeneratingVideo: boolean; onControlsChange: (show: boolean) => void; onEditModalOpen: (tab: string) => void; onToggleVideoPlay: () => void; onTogglePlay: () => void; final?: any; } export function MediaViewer({ currentStep, currentSketchIndex, taskSketch, taskVideos, isVideoPlaying, isPlaying, showControls, isGeneratingSketch, isGeneratingVideo, onControlsChange, onEditModalOpen, onToggleVideoPlay, onTogglePlay, final }: MediaViewerProps) { const mainVideoRef = useRef(null); // 视频播放控制 useEffect(() => { if (mainVideoRef.current) { if (isVideoPlaying) { mainVideoRef.current.play().catch(error => { console.log('视频播放失败:', error); }); } else { mainVideoRef.current.pause(); } } }, [isVideoPlaying]); // 当切换视频时重置视频播放 useEffect(() => { if (mainVideoRef.current) { mainVideoRef.current.currentTime = 0; if (isVideoPlaying) { mainVideoRef.current.play().catch(error => { console.log('视频播放失败:', error); }); } } }, [currentSketchIndex]); // 渲染最终成片 const renderFinalVideo = () => { // 使用真实的final数据,如果没有则使用默认值 const finalVideo = final || { url: 'https://cdn.qikongjian.com/videos/1750389908_37d4fffa-8516-43a3-a423-fc0274f40e8a_text_to_video_0.mp4' }; return (
onControlsChange(true)} onMouseLeave={() => onControlsChange(false)} >
{/* 背景模糊的视频 */} {/* 最终成片视频 */} {/* 操作按钮组 */} {showControls && ( onEditModalOpen('4')} /> )} {/* 视频信息浮层 */}
Final product
{/* 完成标记 */} Task completed
); }; // 渲染视频内容 const renderVideoContent = () => { const currentSketch = taskSketch[currentSketchIndex]; const defaultBgColors = ['RGB(45, 50, 70)', 'RGB(75, 80, 100)', 'RGB(105, 110, 130)']; const bgColors = currentSketch?.bg_rgb || defaultBgColors; return (
onControlsChange(true)} onMouseLeave={() => onControlsChange(false)} > {/* 只在生成过程中或没有视频时使用ProgressiveReveal */} {(isGeneratingVideo || !taskVideos[currentSketchIndex]) ? ( taskVideos[currentSketchIndex] ? (
{/* 背景模糊的图片 */}
background
{/* 视频 */}
) : (
{`Sketch
) ) : ( /* 生成完成后直接显示视频,不使用ProgressiveReveal */
{/* 背景模糊的图片 */}
background
{/* 视频 修复播放没有声音 */}
)} {/* 操作按钮组 */} {showControls && ( onEditModalOpen('3')} /> )} {/* 底部播放按钮 */} {/* 播放时的发光效果 */} {isVideoPlaying && ( )}
); }; // 渲染分镜草图 const renderSketchContent = () => { const currentSketch = taskSketch[currentSketchIndex]; const defaultBgColors = ['RGB(45, 50, 70)', 'RGB(75, 80, 100)', 'RGB(105, 110, 130)']; const bgColors = currentSketch?.bg_rgb || defaultBgColors; return (
onControlsChange(true)} onMouseLeave={() => onControlsChange(false)} > {/* 只在生成过程中或没有分镜图片时使用ProgressiveReveal */} {(isGeneratingSketch || !currentSketch) ? ( currentSketch ? ( {`Sketch ) : (
{/* 动态渐变背景 */} {/* 动态光效 */}
) ) : ( /* 生成完成后直接显示图片,不使用ProgressiveReveal */ {`Sketch )} {/* 操作按钮组 */} {showControls && ( onEditModalOpen('1')} /> )} {/* 底部播放按钮 */} {/* 播放时的发光效果 */} {isPlaying && ( )} {/* 播放进度指示器 */} {isPlaying && ( )}
); }; // 根据当前步骤渲染对应内容 if (Number(currentStep) === 6) { return renderFinalVideo(); } if (Number(currentStep) > 2 && Number(currentStep) < 6) { return renderVideoContent(); } return renderSketchContent(); }