Skip to content

Commit

Permalink
Fix loadAudioStream causing an effect loop.
Browse files Browse the repository at this point in the history
  • Loading branch information
kovipu committed Apr 19, 2024
1 parent 802b3cc commit 0b4acf6
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'tailwindcss/tailwind.css';
import { createRef, useEffect,useRef, useState } from 'react';
import { createRef, useCallback, useEffect, useRef, useState } from 'react';
import { AppProps } from 'next/app';
import Hls from 'hls.js';

Expand All @@ -21,7 +21,7 @@ const MyApp = ({ Component, pageProps }: AppProps) => {
const [volume, setVolume] = useState(0.8);
const [playClicked, setPlayClicked] = useState(false);

const loadAudioStream = () => {
const loadAudioStream = useCallback(() => {
if (Hls.isSupported() && isHlsLive) {
hls.current = new Hls();
hls.current.loadSource(HLS_STREAM_URL);
Expand All @@ -32,11 +32,10 @@ const MyApp = ({ Component, pageProps }: AppProps) => {
) {
audioEl.current.src = AUDIO_STREAM_URL;
}
};
}, [audioEl]);

useEffect(() => {
loadAudioStream();
}, [loadAudioStream]);
// Load the stream on initial page load.
useEffect(loadAudioStream, [loadAudioStream]);

const handlePlayPause = () => {
setPlayClicked(true);
Expand Down

0 comments on commit 0b4acf6

Please sign in to comment.