Skip to content

Instantly share code, notes, and snippets.

View aghyad97's full-sized avatar
๐Ÿ˜„

Aghyad aghyad97

๐Ÿ˜„
View GitHub Profile
@aghyad97
aghyad97 / play-sound-web-api.ts
Created September 8, 2025 17:07
Playing sounds with Web APIs
const audioCtxRef = useRef<AudioContext | null>(null);
const ensureAudio = useCallback(() => {
if (audioCtxRef.current) return audioCtxRef.current;
const Ctx =
(window as any).AudioContext || (window as any).webkitAudioContext;
if (!Ctx) return null;
audioCtxRef.current = new Ctx();
return audioCtxRef.current;