Skip to content

Commit ded4eb4

Browse files
committed
fix(APlayer): stop playing audio when component unmounts
1 parent a1aadee commit ded4eb4

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/hooks/useAudioControl.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ function useCreateAudioElement(
5555

5656
useEffect(() => {
5757
return () => {
58+
const audio = audioElementRef.current
59+
// Properly stop the <audio> playing
60+
// https://stackoverflow.com/a/14836099/6840562
61+
if (audio) {
62+
audio.pause()
63+
audio.currentTime = 0
64+
}
5865
audioElementRef.current = undefined
5966
}
6067
}, [])

0 commit comments

Comments
 (0)