zmxv / react-native-sound

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

Sound doesn't play after loading [Android] #768

Open victoriaSh opened 2 years ago

victoriaSh commented 2 years ago

:beetle: Description Calling "play()" in a success callback stoped working for sounds longer than 1-2 seconds. If I add timeout for playing inside callback it works. I know that it's temporary solution and absolutely the wrong way to resolve it but for some reason sound is not ready to play when it's "loaded" or just interrupted.

This issue might be related to many others active questions there.

:beetle: What is the observed behavior?

Without timeout sound is not playing. Error is null. Sometimes I hear the beginning of the sound (less than 1 sec) and then looks like it has been interrupted. I have no any listeners for pausing it.

:beetle: What is the expected behavior?

Playing sound works without setting timeouts.

:beetle: Please post your code:


music.current = new Sound((Platform.OS === 'ios' ? "sounds/" : "") +'funny.mp3', Sound.MAIN_BUNDLE,
            (error) => { 
                if (error){ 
                    console.log("background sound", error)
                } else {
                    music.current.play()
                }
});

:bulb: Does the problem have a test case?

:bulb: **Possible solution**

:bulb: Is there a workaround?

This code works. But it's the wrong way, I'm not sure how much of a delay is enough for other Android models.


music.current = new Sound((Platform.OS === 'ios' ? "sounds/" : "") +'funny.mp3', Sound.MAIN_BUNDLE,
            (error) => { 
                if (error){ 
                    console.log("background sound", error)
                } else {
                    setTimeout(()=>{music.current.play()},800);
                }
});

:bulb: If the bug is confirmed, would you be willing to create a pull request?

Is your issue with...

Are you using...

Which versions are you using?

Does the problem occur on...

If your problem is happening on a device, which device?

punndcoder28 commented 2 years ago

Hi @victoriaSh i am facing this issue as well on our production app but it is not consistent. How did you come up with the work around?