Reputation: 11394
I am getting a React-Native app working on a MacBook. The app previously worked for Android. I have basically restarted a project with the latest react-native modules. However, I can not seem to get the audio working.
I have the following function, which is triggered on a click event:
playSound(soundfile) {
var s = new Sound(RNFS.DocumentDirectoryPath + '/audio/' + soundfile, Sound.MAIN_BUNDLE, (e) => {
if (e) {
console.log('error', e);
} else {
console.log('duration', s.getDuration());
s.play(()=>{
s.release()
console.log("Sound Resource Released")
})
}
});
}
I have verified that the soundfile does exist and the path is correct. However, the above code is throwing an error:
{code: "ENSOSSTATUSERRORDOMAIN2003334207", message: "The operation couldn’t be completed. (OSStatus error 2003334207.)", nativeStackIOS: Array(17), domain: "NSOSStatusErrorDomain", userInfo: {…}}
What exactly is this error telling me and what can I do to fix it?
Updated for clarification:
The sound file is not a static sound file so is not packaged with the app. Instead a user can choose a zipped game pack to download from the game server. The game packs consist of both images, audio, and data files. The zip file is downloaded and uncompressed. Both the images and data files work fine. However, for whatever reason the audio is just not playing. Again I have confirmed that the audio file does actually exist at that path.
Here is the nativeStackIOS portion of the error:
0: "0 App4 0x0000000106ee30b7 RCTJSErrorFromCodeMessageAndNSError + 135"
1: "1 App4 0x0000000106ee2fe3 RCTJSErrorFromNSError + 275"App4
2: "2 App4 0x00000001070fdff8 -[RNSound prepare:withKey:withOptions:withCallback:] + 1624"
3: "3 CoreFoundation 0x0000000109ac303c __invoking___ + 140"
4: "4 CoreFoundation 0x0000000109ac04d5 -[NSInvocation invoke] + 325"
5: "5 CoreFoundation 0x0000000109ac0926 -[NSInvocation invokeWithTarget:] + 54"
6: "6 App4 0x0000000106e724ca -[RCTModuleMethod invokeWithBridge:module:arguments:] + 2810"
7: "7 App4 0x0000000106f2e306 _ZN8facebook5reactL11invokeInnerEP9RCTBridgeP13RCTModuleDatajRKN5folly7dynamicE + 790"
8: "8 App4 0x0000000106f2de1f _ZZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEiENK3$_0clEv + 127"
9: "9 App4 0x0000000106f2dd99 ___ZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEi_block_invoke + 25"
10: "10 libdispatch.dylib 0x000000010d0ac4e1 _dispatch_call_block_and_release + 12"
11: "11 libdispatch.dylib 0x000000010d0ad54b _dispatch_client_callout + 8"
12: "12 libdispatch.dylib 0x000000010d0b401c _dispatch_lane_serial_drain + 720"
13: "13 libdispatch.dylib 0x000000010d0b4b5f _dispatch_lane_invoke + 401"
14: "14 libdispatch.dylib 0x000000010d0bd9a8 _dispatch_workloop_worker_thread + 645"
15: "15 libsystem_pthread.dylib 0x000000010d49760b _pthread_wqthread + 409"
16: "16 libsystem_pthread.dylib 0x000000010d497405 start_wqthread + 13"
Upvotes: 3
Views: 3499
Reputation: 11394
According to some documentation that I found (I'm not sure where to find the official documentation) it says the syntax for the constructor is as follows:
constructor(filename, basePath, onError)
Where basePath is the optional base path of the file. The options for basePath are:
Omit this or pass an empty string if filename is an absolute path. Otherwise, you may use one of the predefined directories: Sound.MAIN_BUNDLE, Sound.DOCUMENT, Sound.LIBRARY, Sound.CACHES.
Since I was using an absolute path, I replaced Sound.MAIN_BUNDLE
with an empty string.
So I changed:
var s = new Sound(RNFS.DocumentDirectoryPath + '/audio/' + soundfile, Sound.MAIN_BUNDLE, (e) => { ... }
to:
var s = new Sound(RNFS.DocumentDirectoryPath + '/audio/' + soundfile, '', (e) => { ... }
Everything is working fine now. The one question I have, however, is why it worked fine with Android when specifying the absolute path and Sound.MAIN_BUNDLE, but does not work with IOS.
Upvotes: 3
Reputation: 1385
This error occurs when you are trying to access a file which is not present in the specified folder or can not be downloaded from a network.
Please test with a local audio file or like suggested to whitelist the domain hosting the audio file or use NSAllowsArbitraryLoads
to whitelist everything if needed.
Upvotes: 0