diff --git a/frontend/src/providers/audio-provider.tsx b/frontend/src/providers/audio-provider.tsx new file mode 100644 index 0000000..964f2a5 --- /dev/null +++ b/frontend/src/providers/audio-provider.tsx @@ -0,0 +1,45 @@ +"use client"; + +import type React from "react"; +import { createContext, useCallback, useContext, useState } from "react"; + +interface AudioContextType { + isGlobalMuted: boolean; + activeVideoId: string | null; + toggleGlobalMute: () => void; + setActiveVideo: (id: string | null) => void; +} + +const AudioContext = createContext(undefined); + +export function AudioProvider({ children }: { children: React.ReactNode }) { + const [isGlobalMuted, setIsGlobalMuted] = useState(true); + const [activeVideoId, setActiveVideoId] = useState(null); + + const toggleGlobalMute = useCallback(() => { + setIsGlobalMuted((prev) => !prev); + }, []); + + const setActiveVideo = useCallback((id: string | null) => { + setActiveVideoId(id); + if (id !== null) { + setIsGlobalMuted(false); + } + }, []); + + return ( + + {children} + + ); +} + +export function useAudio() { + const context = useContext(AudioContext); + if (context === undefined) { + throw new Error("useAudio must be used within an AudioProvider"); + } + return context; +}