import React, { useEffect, useRef, useContext, useState } from "react"; import { motion, AnimatePresence } from "framer-motion"; import { PlayIcon, PauseIcon, SpeakerWaveIcon, SpeakerXMarkIcon, Cog6ToothIcon, ArrowsPointingOutIcon, ArrowsPointingInIcon, ChevronUpDownIcon, SunIcon, } from "@heroicons/react/24/solid"; import { VideoPlayerContext } from "./VideoPlayer"; import { formatTime } from "./utlis"; import { PlaybackSpeed } from "./type"; import Volume from "./ControlButtons/Volume"; import Brightness from "./ControlButtons/Brightness"; import Speed from "./ControlButtons/Speed"; import Play from "./ControlButtons/Play"; import Setting from "./ControlButtons/Setting"; import FullScreen from "./ControlButtons/FullScreen"; import TimeLine from "./ControlButtons/TimeLine"; export const Controls = () => { const { showControls, setShowControls, isSettingsOpen, setIsSettingsOpen, playbackSpeed, setPlaybackSpeed, videoRef, isReady, setIsReady, isPlaying, setIsSpeedOpen, isSpeedOpen, setIsPlaying, bufferingState, setBufferingState, volume, setVolume, isMuted, setIsMuted, loadingProgress, setLoadingProgress, currentTime, setCurrentTime, duration, setDuration, brightness, setBrightness, isDragging, setIsDragging, isHovering, isBrightnessOpen, setIsBrightnessOpen, setIsHovering, progressRef, } = useContext(VideoPlayerContext); // 控制栏显示逻辑 useEffect(() => { let timer: number; if (!isHovering && !isDragging) { timer = window.setTimeout(() => { setShowControls(false); }, 2000); } return () => { if (timer) window.clearTimeout(timer); }; }, [isHovering, isDragging]); return ( {/* 进度条 */} {/* 控制按钮区域 */}
{/* 播放/暂停按钮 */} {/* 时间显示 */} {duration && ( {formatTime(currentTime)} / {formatTime(duration)} )}
{/* 右侧控制按钮 */}
{/* 音量 */} {/* 亮度 */} {/* 倍速控制 */} {/* 设置按钮 */} {/* 全屏按钮 */}
); }; export default Controls;