import { createContext, useContext, ReactNode } from 'react' interface VideoContextValue { /** 视频是否正在播放 */ isVideoPlaying: boolean /** 内容是否可见 */ isContentVisible: boolean } const VideoContext = createContext(undefined) export const VideoProvider = ({ children, isVideoPlaying, isContentVisible, }: { children: ReactNode isVideoPlaying: boolean isContentVisible: boolean }) => { return ( {children} ) } export const useVideoContext = () => { const context = useContext(VideoContext) if (context === undefined) { throw new Error('useVideoContext must be used within a VideoProvider') } return context } /** * 安全地获取视频上下文,如果不在 VideoProvider 中则返回 null */ export const useVideoContextSafe = () => { const context = useContext(VideoContext) return context ?? null }