diff --git a/js/src/features/playback/media-particle-view.tsx b/js/src/features/playback/media-particle-view.tsx index 773ea94..4153333 100644 --- a/js/src/features/playback/media-particle-view.tsx +++ b/js/src/features/playback/media-particle-view.tsx @@ -43,22 +43,17 @@ export function MediaParticleView({ ); const cacheDownloadUrl = usePlaybackStore((s) => s.cacheDownloadUrl); const paused = usePlaybackStore((s) => s.paused); - const [url, setUrl] = useState(cachedUrl ?? null); const [error, setError] = useState(null); const videoRef = useRef(null); const audioRef = useRef(null); - const [audioEl, setAudioEl] = useState(null); const [currentTimeMs, setCurrentTimeMs] = useState(0); const data = particle.data as MediaParticleData; const isAudio = data.mime_type?.startsWith("audio/"); - const audioSource = useAudioSource(isAudio ? audioEl : null); - useEffect(() => { if (cachedUrl) { - setUrl(cachedUrl); return; } @@ -68,7 +63,6 @@ export function MediaParticleView({ .then((downloadUrl) => { if (cancelled) return; cacheDownloadUrl(particle.id, downloadUrl); - setUrl(downloadUrl); }) .catch(() => { if (!cancelled) setError("Failed to load media"); @@ -77,40 +71,28 @@ export function MediaParticleView({ return () => { cancelled = true; }; - }, [particle.id, cachedUrl, cacheDownloadUrl]); + }, [particle.id, cacheDownloadUrl]); - // Start audio playback once the AudioContext source is ready + // Handle pause/resume useEffect(() => { - const el = audioRef.current; - if (!el || !audioSource) return; - - if (!paused) { - el.play().catch(() => {}); + var el: HTMLVideoElement | HTMLAudioElement | null = null; + if (isAudio) { + el = audioRef.current; + } else { + el = videoRef.current; } - }, [audioSource, paused]); - // Handle video pause/resume - useEffect(() => { - const el = videoRef.current; if (!el) return; if (paused) { el.pause(); } else { - el.play().catch(() => {}); + el.play().catch(() => { + console.warn("Playback failed", { particleId: particle.id }); + }); } }, [paused]); - // Handle audio pause/resume (after initial play) - useEffect(() => { - const el = audioRef.current; - if (!el || !audioSource) return; - - if (paused) { - el.pause(); - } - }, [paused, audioSource]); - if (error) { return (
@@ -119,7 +101,7 @@ export function MediaParticleView({ ); } - if (!url) { + if (!cachedUrl) { return ; } @@ -127,22 +109,16 @@ export function MediaParticleView({ return (