React-native-sound: Can not play sound normally

Created on 9 Dec 2017  路  4Comments  路  Source: zmxv/react-native-sound

Exception message

code: "ENSOSSTATUSERRORDOMAIN2003334207", message: "The operation couldn鈥檛 be completed. (OSStatus error 2003334207.)"

PLIST

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>localhost</key>
        <dict>
            <key>NSExceptionAllowsInsecureHTTPLoads</key>
            <true/>
        </dict>
    </dict>

Code

    sound = new Sound('http://www.noiseaddicts.com/samples_1w72b820/4923.mp3', Sound.MAIN_BUNDLE, (error) => {
        if (error) {
            console.warn('failed to load sound, ', error);
        } else {
            // sound.play();
            this.setState({
                isPlaying: true,
            });
        }
    });

Most helpful comment

I think you should replace Sound.MAIN_BUNDLE with '' (empty string). And for iOS - add www.noiseaddicts.com to exception domains

All 4 comments

I think you should replace Sound.MAIN_BUNDLE with '' (empty string). And for iOS - add www.noiseaddicts.com to exception domains

334

@Andrfas Solution worked fine, Thanks!

For iOS what worked for me is the following:

  1. Checked that my resource file was being played in xCode

    • Open xCode

    • Select the file

    • Click play in the xCode player

  2. Once it was playing sound (had issues with some files, possibly encoding),

    • Add the file as resource (Make sure is in Build Phases)

  3. Compile the project in xCode and run it from there

    • Note: Every time you change the resources or expect new resources you need to compile your Native application either by doing it from xCode or npm run ios

This is my code:

const sound = new Sound(
    "myFile.mp3",
    Sound.MAIN_BUNDLE,
    error => {
      if (error) {
        console.log("failed to load the sound", error);
        return;
      }
      sound.play(() => sound.release());
    }
  );
// The play dispatcher
sound.play();
Was this page helpful?
0 / 5 - 0 ratings