zmxv / react-native-sound

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

No sound in release build on iOS with v0.11.1 #742

Open webyonet opened 3 years ago

webyonet commented 3 years ago

:beetle: Description

There is no problem in debug mode, but there is no sound in release mode (real device). There is no such problem with v0.11.0

:beetle: What is the observed behavior?

No sound

:beetle: What is the expected behavior?

sound playing

:beetle: Please post your code:

const media = new Sound(source, error => {
                if (error) {
                    console.log('failed to load the sound', error);
                    return;
                }

                media.play((success) => {
                    media.release();
                });
});

:bulb: Does the problem have a test case?

:bulb: **Possible solution**

:bulb: Is there a workaround?

: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?

akenger commented 3 years ago

I had a similar issue and thought it was a release mode vs not problem but it turns out that my local dev environment was using 0.11.0 and the build server did clean npm installs each time and installed 0.11.1. We have the same problem as you just running 0.11.1 at all. Going to revert to 0.11.0 for now.

Megatron4537 commented 2 years ago

Same thing happened to me, on iOS but not on Android and this patch fixed it for me.

diff --git a/node_modules/react-native-sound/sound.js b/node_modules/react-native-sound/sound.js
index 33e6157..3391b11 100644
--- a/node_modules/react-native-sound/sound.js
+++ b/node_modules/react-native-sound/sound.js
@@ -106,7 +106,7 @@ Sound.prototype.isLoaded = function() {

 Sound.prototype.play = function(onEnd) {
   if (this._loaded) {
-    RNSound.play(this._key, onEnd ? (successfully) => onEnd(successfully) : null);
+    RNSound.play(this._key,  (successfully) => onEnd && onEnd(successfully) );
   } else {
     onEnd && onEnd(false);
   }