Skip to content

Conversation

dhairyasenjaliya
Copy link

No description provided.

@EmilJunker
Copy link

This PR is the only way I could get react-native-sound to work with React Native 0.79. I installed it with npm install ngandhy/react-native-sound#26f8ecb and successfully built and tested my app.

I also tried the latest released version npm install react-native-sound, the latest tag on GitHub npm install zmxv/react-native-sound#v0.12.0 as well as the latest commit from master npm install zmxv/react-native-sound#bc92152, but none of them worked.

Thank you very much for this PR. I hope it can get merged and this library can be put in a working state again.

@RomualdPercereau
Copy link
Collaborator

Hello @EmilJunker & @dhairyasenjaliya
Thank you for this PR and the work on!

Could you please tell us more about why it's not working with the latest master branch? Would be amazing to be able to merge with this branch and make @zmxv update it on npm! 💪

@EmilJunker
Copy link

@RomualdPercereau Thank you for your interest in getting this issue resolved. Here is an overview of the errors I'm seeing:


When using the latest released version installed via npm install react-native-sound, I get this runtime error on both iOS and Android:

Warning: TypeError: _$$_REQUIRE(_dependencyMap[1], "(...)aries/Image/resolveAssetSource") is not a function (it is Object)

When using the latest tagged version installed via npm install zmxv/react-native-sound#v0.12.0, I get these build errors:

Screenshot iOS build error

{D9EF2F3F-3EF3-4720-8B32-B762DC9DD5BF}

Android build log
> Task :react-native-sound:processDebugManifest                                                                                             
package="com.zmxv.RNSound" found in source AndroidManifest.xml: C:\Users\emil.junker\git_repos\signal2x\node_modules\react-native-sound\android\src\main\AndroidManifest.xml.
Setting the namespace via the package attribute in the source AndroidManifest.xml is no longer supported, and the value is ignored.
Recommendation: remove package="com.zmxv.RNSound" from the source AndroidManifest.xml: C:\Users\emil.junker\git_repos\signal2x\node_modules\react-native-sound\android\src\main\AndroidManifest.xml.

> Task :react-native-sound:compileDebugJavaWithJavac

> Task :app:compileDebugJavaWithJavac FAILED                                                                                                

[Incubating] Problems report is available at: file:///C:/Users/emil.junker/git_repos/signal2x/android/build/reports/problems/problems-report.html

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

For more on this, please refer to https://docs.gradle.org/8.13/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.
335 actionable tasks: 40 executed, 295 up-to-date

info 💡 Tip: Make sure that you have set up your development environment correctly, by running npx react-native doctor. To read more about doctor command visit: https://github.com/react-native-community/cli/blob/main/packages/cli-doctor/README.md#doctor 

C:\Users\emil.junker\git_repos\signal2x\node_modules\react-native-sound\android\src\main\java\com\zmxv\RNSound\RNSoundModule.java:350: warning: [removal] onCatalystInstanceDestroy() in NativeModule has been deprecated and marked for removal
  public void onCatalystInstanceDestroy() {
              ^
Note: C:\Users\emil.junker\git_repos\signal2x\node_modules\react-native-sound\android\src\main\java\com\zmxv\RNSound\RNSoundModule.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 warning
C:\Users\emil.junker\git_repos\signal2x\android\app\build\generated\autolinking\src\main\java\com\facebook\react\PackageList.java:38: error: cannot find symbol
import com.zmxv.RNSound.SoundPackage;
                       ^
  symbol:   class SoundPackage
  location: package com.zmxv.RNSound
C:\Users\emil.junker\git_repos\signal2x\android\app\build\generated\autolinking\src\main\java\com\facebook\react\PackageList.java:98: error: cannot find symbol
      new SoundPackage(),
          ^
  symbol:   class SoundPackage
  location: class PackageList
2 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler output below.
  C:\Users\emil.junker\git_repos\signal2x\android\app\build\generated\autolinking\src\main\java\com\facebook\react\PackageList.java:38: error: cannot find symbol
  import com.zmxv.RNSound.SoundPackage;
                         ^
    symbol:   class SoundPackage
    location: package com.zmxv.RNSound
  C:\Users\emil.junker\git_repos\signal2x\android\app\build\generated\autolinking\src\main\java\com\facebook\react\PackageList.java:98: error: cannot find symbol
        new SoundPackage(),
            ^
    symbol:   class SoundPackage
    location: class PackageList
  2 errors

* Try:
> Check your code and dependencies to fix the compilation error(s)
> Run with --scan to get full insights.

BUILD FAILED in 1m 20s
error Failed to install the app. Command failed with exit code 1: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
C:\Users\emil.junker\git_repos\signal2x\node_modules\react-native-sound\android\src\main\java\com\zmxv\RNSound\RNSoundModule.java:350: warning: [removal] onCatalystInstanceDestroy() in NativeModule has been deprecated and marked for removal public void onCatalystInstanceDestroy() { ^ Note: C:\Users\emil.junker\git_repos\signal2x\node_modules\react-native-sound\android\src\main\java\com\zmxv\RNSound\RNSoundModule.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. 1 warning C:\Users\emil.junker\git_repos\signal2x\android\app\build\generated\autolinking\src\main\java\com\facebook\react\PackageList.java:38: error: cannot find symbol
import com.zmxv.RNSound.SoundPackage; ^ symbol: class SoundPackage location: package com.zmxv.RNSound C:\Users\emil.junker\git_repos\signal2x\android\app\build\generated\autolinking\src\main\java\com\facebook\react\PackageList.java:98: error: cannot find symbol new SoundPackage(), ^ symbol: class SoundPackage location: class PackageList 2 errors FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:compileDebugJavaWithJavac'. > Compilation failed; see the compiler output below. C:\Users\emil.junker\git_repos\signal2x\android\app\build\generated\autolinking\src\main\java\com\facebook\react\PackageList.java:38: error: cannot find symbol import com.zmxv.RNSound.SoundPackage; ^ symbol: class SoundPackage location: package com.zmxv.RNSound C:\Users\emil.junker\git_repos\signal2x\android\app\build\generated\autolinking\src\main\java\com\facebook\react\PackageList.java:98: error: cannot find symbol new SoundPackage(), ^ symbol: class SoundPackage location: class PackageList 2 errors * Try: > Check your code and dependencies to fix the compilation error(s) > Run with --scan to get full insights. BUILD FAILED in 1m 20s.
info Run CLI with --verbose flag for more details.

When using the latest version from master installed via npm install zmxv/react-native-sound#bc92152, I get the same build error on iOS, and I get this runtime error on Android:

Warning: TypeError: filename.startsWith is not a function (it is undefined)

I'm using React Native 0.79.1 with the new architechture disabled.

@RomualdPercereau
Copy link
Collaborator

Hello @dhairyasenjaliya and @EmilJunker,
I'm sorry, this current PR is in conflict with current master. (19 commits behinds), I don't have time to fix it.

If anyone can update this PR to make it works with the new architecture, it would be wonderful!

@EmilJunker
Copy link

I'm sorry, this current PR is in conflict with current master. (19 commits behinds), I don't have time to fix it.

The fact that this PR is 19 commits behind the current master is precisely the reason why it's working. This PR is basically version 0.11.2 of the library with an added fix for the Warning: TypeError: _$$_REQUIRE(_dependencyMap[1] error I mentioned above. Merging this PR into master would actually be unnecessary because among the 19 commits added to master since then, there is also one that fixes this error.

The actual problem is that some of those 19 commits seem to have introduced new errors (see my comment above #861 (comment)). Hence, the priority should be to fix these errors and then release a new and working version of this library on npm.

@RomualdPercereau
Copy link
Collaborator

Thank you very much for the feedback @EmilJunker. It is indeed strange that this error is occurring on the master branch. The issue with rolling back these 19 commits is that we would lose the compatibility added as part of issue #850 (@SolankiYogesh) for the new architecture.

By addressing the new errors introduced in these fix, we could establish a clean baseline and then proceed to publish it on npm.

@dhairyasenjaliya
Copy link
Author

Hey @RomualdPercereau its quick fix I will create a new PR for this particular pr we hade some old changes which is not needed for this bug

@EmilJunker
Copy link

I'm a JavaScript/TypeScript dev and don't know much about native Android/iOS app development. But if someone could just make a PR on top of the current master that fixes the iOS build error seen here
{D9EF2F3F-3EF3-4720-8B32-B762DC9DD5BF}
and the Android runtime error seen here

Warning: TypeError: filename.startsWith is not a function (it is undefined)

both of which don't look too difficult, it would be great.

@r0h0gg6
Copy link

r0h0gg6 commented Jul 13, 2025

Any update on this?

@EmilJunker
Copy link

I just realized the reason why I get the Warning: TypeError: filename.startsWith is not a function (it is undefined) runtime error on Android is because I pass an object to the Sound constructor like this:

import bell from './../assets/sounds/bell.mp3';
bellSound = new Sound(bell);

instead of passing the file path:

bellSound = new Sound('./../assets/sounds/bell.mp3');

Therefore, this line of code in src/index.ts throws an exception. In the past, it was definitely possible to pass an mp3 file object and everything was working fine, but it looks like the commit 935ba2b broke it.

However, even if I change my code and pass the file path as bellSound = new Sound('./../assets/sounds/bell.mp3') then I still get a runtime error on Android when using the latest version from master (npm install zmxv/react-native-sound#bc92152) with React Native 0.80.1 and the new archirecture disabled. When I do the same with the version from this PR (npm install ngandhy/react-native-sound#26f8ecb) then I don't get that runtime error, but the sound still doesn't actually play when I call bellSound.play() it just stays silent. So I have to pass it as an object after all. What a mess this library is 😿

@DK-AC
Copy link

DK-AC commented Jul 28, 2025

adding the patch helped me solve the problem react-native-sound+0.11.2.patch
"react-native-sound": "^0.11.2",
"react-native": "0.79.3",

diff --git a/node_modules/react-native-sound/RNSound/RNSound.m b/node_modules/react-native-sound/RNSound/RNSound.m
index df3784e..d1b4358 100644
--- a/node_modules/react-native-sound/RNSound/RNSound.m
+++ b/node_modules/react-native-sound/RNSound/RNSound.m
@@ -21,19 +21,19 @@ - (void)audioSessionChangeObserver:(NSNotification *)notification {
         [userInfo[@"AVAudioSessionInterruptionTypeKey"] longValue];
     AVAudioPlayer *player = [self playerForKey:self._key];
     if (audioSessionInterruptionType == AVAudioSessionInterruptionTypeEnded) {
-        if (player && player.isPlaying) {
+        if (player) {
             [player play];
             [self setOnPlay:YES forPlayerKey:self._key];
         }
     }
-    if (audioSessionRouteChangeReason ==
+    else if (audioSessionRouteChangeReason ==
         AVAudioSessionRouteChangeReasonOldDeviceUnavailable) {
         if (player) {
             [player pause];
             [self setOnPlay:NO forPlayerKey:self._key];
         }
     }
-    if (audioSessionInterruptionType == AVAudioSessionInterruptionTypeBegan) {
+    else if (audioSessionInterruptionType == AVAudioSessionInterruptionTypeBegan) {
         if (player) {
             [player pause];
             [self setOnPlay:NO forPlayerKey:self._key];
@@ -198,18 +198,17 @@ - (NSDictionary *)constantsToExport {
     NSError *error;
     NSURL *fileNameUrl;
     AVAudioPlayer *player;
-    NSString* fileNameEscaped = [fileName stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

-    if ([fileNameEscaped hasPrefix:@"http"]) {
-        fileNameUrl = [NSURL URLWithString:fileNameEscaped];
+    if ([fileName hasPrefix:@"http"]) {
+        fileNameUrl = [NSURL URLWithString:fileName];
         NSData *data = [NSData dataWithContentsOfURL:fileNameUrl];
         player = [[AVAudioPlayer alloc] initWithData:data error:&error];
-    } else if ([fileNameEscaped hasPrefix:@"ipod-library://"]) {
-        fileNameUrl = [NSURL URLWithString:fileNameEscaped];
+    } else if ([fileName hasPrefix:@"ipod-library://"]) {
+        fileNameUrl = [NSURL URLWithString:fileName];
         player = [[AVAudioPlayer alloc] initWithContentsOfURL:fileNameUrl
                                                         error:&error];
     } else {
-        fileNameUrl = [NSURL URLWithString:fileNameEscaped];
+        fileNameUrl = [NSURL URLWithString:fileName];
         player = [[AVAudioPlayer alloc] initWithContentsOfURL:fileNameUrl
                                                         error:&error];
     }
@@ -245,7 +244,12 @@ - (NSDictionary *)constantsToExport {
         addObserver:self
            selector:@selector(audioSessionChangeObserver:)
                name:AVAudioSessionRouteChangeNotification
-             object:nil];
+             object:[AVAudioSession sharedInstance]];
+    [[NSNotificationCenter defaultCenter]
+        addObserver:self
+           selector:@selector(audioSessionChangeObserver:)
+               name:AVAudioSessionInterruptionNotification
+             object:[AVAudioSession sharedInstance]];
     self._key = key;
     AVAudioPlayer *player = [self playerForKey:key];
     if (player) {
diff --git a/node_modules/react-native-sound/sound.js b/node_modules/react-native-sound/sound.js
index c9bcbaf..f4c6583 100644
--- a/node_modules/react-native-sound/sound.js
+++ b/node_modules/react-native-sound/sound.js
@@ -4,7 +4,10 @@ var ReactNative = require('react-native');
 var RNSound = ReactNative.NativeModules.RNSound;
 var IsAndroid = RNSound.IsAndroid;
 var IsWindows = RNSound.IsWindows;
-var resolveAssetSource = require("react-native/Libraries/Image/resolveAssetSource");
+var resolveAssetSourceModule = require("react-native/Libraries/Image/resolveAssetSource");
+var resolveAssetSource = resolveAssetSourceModule && resolveAssetSourceModule.__esModule
+  ? resolveAssetSourceModule.default
+  : resolveAssetSourceModule;
 var eventEmitter = new ReactNative.NativeEventEmitter(RNSound);

 var nextKey = 0;

@RomualdPercereau
Copy link
Collaborator

Thank you @DK-AC, if you could push a PR, would be amazing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants