From 465e3bf2242546f56c670c2aeeb9479c954d5ba0 Mon Sep 17 00:00:00 2001 From: 0x1eef <0x1eef@protonmail.com> Date: Wed, 12 Jul 2023 22:57:49 -0300 Subject: [PATCH] Try to fix audio stream on iOS --- src/js/components/Stream.tsx | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/js/components/Stream.tsx b/src/js/components/Stream.tsx index 742a81e87..c8a7f4d9f 100644 --- a/src/js/components/Stream.tsx +++ b/src/js/components/Stream.tsx @@ -23,8 +23,10 @@ export function Stream({ reciter, surah, stream, locale, slice, endOfStream, isP { 'overflowY': 'auto' } : { 'overflowY': 'hidden' }; const audioRef = useRef(null); + const { url: baseUrl } = reciter; + const ayah = stream[stream.length-1]; + const src = `${baseUrl}/${surah.id}/${ayah.id}.mp3`; const ayat = stream.map((ayah: Quran.Ayah) => { - const { url: baseUrl } = reciter; return (
  • @@ -35,12 +37,10 @@ export function Stream({ reciter, surah, stream, locale, slice, endOfStream, isP {formatNumber(ayah.id, locale)}

    {ayah.text}

    -
  • ); }); - useEffect(() => { const ul: HTMLElement = document.querySelector('ul.stream')!; if (slice.coversOneAyah) { @@ -63,9 +63,19 @@ export function Stream({ reciter, surah, stream, locale, slice, endOfStream, isP } }, [stream, isPaused, soundOn]); + useEffect(() => { + const audio = audioRef.current; + if (audio) { + audio.addEventListener('ended', () => { + audio.setAttribute('src', src); + }); + } + }, [audioRef.current]); + return ( ); }