Skip to content

Commit

Permalink
make loop & autoplay trigger reload
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarek committed Oct 13, 2023
1 parent 1d99b7c commit 6fd1db6
Showing 1 changed file with 4 additions and 20 deletions.
24 changes: 4 additions & 20 deletions src/components/shared/AudioViewer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ const AudioViewer = ({
if (!waveform.current) return;

if (autoplay) waveform.current.play();

(waveform.current.backend as unknown as WebAudio).media.loop = looping;
});

Expand Down Expand Up @@ -368,7 +369,7 @@ const AudioViewer = ({
} else {
redrawTimeline(timelineContainer.current, waveform.current);
}
}, [url, peaks]);
}, [url, peaks, autoplay, looping]);

const switchActiveWidget = () => {
if (!waveform.current?.isReady) return;
Expand Down Expand Up @@ -417,23 +418,6 @@ const AudioViewer = ({
}
};

const toggleRepeat = (enabled: boolean) => {
if (waveform.current?.isReady) {
if (!waveform.current) return;

setLooping(enabled);
(waveform.current.backend as unknown as WebAudio).media.loop = enabled;
}
};

const toggleAutoPlay = (enabled: boolean) => {
if (waveform.current?.isReady) {
if (!waveform.current) return;
setAutoplay(enabled);
//waveform.current.backend.autoplay = true;//!waveform.current.autoplay;
}
};

const fitToScreen = () => {
if (!waveform.current?.isReady) return;

Expand Down Expand Up @@ -598,8 +582,8 @@ const AudioViewer = ({
<MenuBar
isLooping={looping}
shouldAutostart={autoplay}
onChangeLoop={toggleRepeat}
onChangeAutostart={toggleAutoPlay}
onChangeLoop={setLooping}
onChangeAutostart={setAutoplay}
/>
</Container>
);
Expand Down

0 comments on commit 6fd1db6

Please sign in to comment.