zmxv / react-native-sound

React Native module for playing sound clips
MIT License
2.78k stars 747 forks source link

Not working in conjunction with useEffect #814

Open jordangrant opened 1 year ago

jordangrant commented 1 year ago

Appreciate the work done here but ran into many issues playing sound effects while listening with useEffect ala:

 useEffect(() => {
       playSound(battle?.animation)
    }, [battle?.animation]);

and with .aac files crashing https://github.com/zmxv/react-native-sound/issues/802

and with the error "playback failed due to audio decoding errors"

tried useRef to no avail https://github.com/zmxv/react-native-sound/issues/728#issuecomment-901830211

and different syntax, moved things around, you get the idea. tested on iOS device.

Had quicker and easier success with react-native-video: https://github.com/react-native-video/react-native-video

Thanks for the good times though

tdammy92 commented 1 year ago

hi @jordangrant I think our issues are similar am trying to stop the current song when the user is leaving the screen.

which am doing inside a useEffect. but it not working.

did you find a solution around yours ?

jordangrant commented 1 year ago

@tdammy92 no solution with this library, simply using react-native-video with invisible views, and mp3, mp4 and m4a files works absolutely perfectly and great settings to control it too.

tdammy92 commented 1 year ago

@jordangrant, Add the audio as part of the dependency. it should work

useEffect(() => { playSound(battle?.animation) }, [battle?.animation,audio]);

BraveEvidence commented 1 year ago

This will help https://www.youtube.com/watch?v=vVI7ZAZq5e0