React-native-sound: The operation couldn鈥檛 be completed. (OSStatus error -10875.)

Created on 7 Nov 2017  路  11Comments  路  Source: zmxv/react-native-sound

url: http://onvjhqfse.bkt.clouddn.com/uBKR6PpbUxLdT2IuZ2JTWau88NI=/Fj7HPw5pEP_SYS8D06ZMrMG722IV

{ 
  code: 'ENSOSSTATUSERRORDOMAIN-10875',
  message: 'The operation couldn鈥檛 be completed. (OSStatus error -10875.)',
  nativeStackIOS: 
   [ '0   ListenLiteApp                       0x0000000104d65dc6 RCTJSErrorFromCodeMessageAndNSError + 134',
     '1   ListenLiteApp                       0x0000000104d65cf3 RCTJSErrorFromNSError + 275',
     '2   ListenLiteApp                       0x0000000104f01215 -[RNSound prepare:withKey:withOptions:withCallback:] + 1493',
     '3   CoreFoundation                      0x000000010716856c __invoking___ + 140',
     '4   CoreFoundation                      0x0000000107168440 -[NSInvocation invoke] + 320',
     '5   CoreFoundation                      0x0000000107180df6 -[NSInvocation invokeWithTarget:] + 54',
     '6   ListenLiteApp                       0x0000000104d1597c -[RCTModuleMethod invokeWithBridge:module:arguments:] + 2796',
     '7   ListenLiteApp                       0x0000000104da9700 _ZN8facebook5react15RCTNativeModule11invokeInnerEjOKN5folly7dynamicE + 784',
     '8   ListenLiteApp                       0x0000000104da92dc _ZZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEiENK3$_0clEv + 60',
     '9   ListenLiteApp                       0x0000000104da9299 ___ZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEi_block_invoke + 25',
     '10  libdispatch.dylib                   0x000000010bbc3273 _dispatch_call_block_and_release + 12',
     '11  libdispatch.dylib                   0x000000010bbc42b5 _dispatch_client_callout + 8',
     '12  libdispatch.dylib                   0x000000010bbcbe3f _dispatch_queue_serial_drain + 654',
     '13  libdispatch.dylib                   0x000000010bbcc690 _dispatch_queue_invoke + 329',
     '14  libdispatch.dylib                   0x000000010bbc8d94 _dispatch_queue_override_invoke + 477',
     '15  libdispatch.dylib                   0x000000010bbcea72 _dispatch_root_queue_drain + 568',
     '16  libdispatch.dylib                   0x000000010bbce7dc _dispatch_worker_thread3 + 119',
     '17  libsystem_pthread.dylib             0x000000010c07f5a2 _pthread_wqthread + 1299',
     '18  libsystem_pthread.dylib             0x000000010c07f07d start_wqthread + 13' ],
  domain: 'NSOSStatusErrorDomain',
  userInfo: {} 
}

Most helpful comment

Just wrap basePath in encodeURIComponent and everything will work

var SOUND_PRESS = new Sound(getSoundName('sound_press'), encodeURIComponent(Sound.MAIN_BUNDLE));

All 11 comments

I add NSAllowsArbitraryLoads(YES) to Info.plist, and then is work fine.

still not working for me even add the NSAllowsArbitraryLoads

Maybe a little bit late, but my Buildable name was containing spaces like Appname Bla Dev.app
After changing that to AppnameBlaDev.app the sound was loaded correct.

@lecramfriedrich thanks, that was my solution when I created other target.

@lecramfriedrich what is the "Buildable name"?

Just wrap basePath in encodeURIComponent and everything will work

var SOUND_PRESS = new Sound(getSoundName('sound_press'), encodeURIComponent(Sound.MAIN_BUNDLE));

Just wrap basePath in encodeURIComponent and everything will work

var SOUND_PRESS = new Sound(getSoundName('sound_press'), encodeURIComponent(Sound.MAIN_BUNDLE));

@vacoo where are you getting getSoundName and encodeURIComponent from?

Just wrap basePath in encodeURIComponent and everything will work

var SOUND_PRESS = new Sound(getSoundName('sound_press'), encodeURIComponent(Sound.MAIN_BUNDLE));

@vacoo where are you getting getSoundName and encodeURIComponent from?

ios supports aiff, and Android supports mp3. So I made this function

function getSoundName(name: string): string {
    return Platform.OS === 'ios' ? name + '.aiff' : name + '.mp3';
}

encodeURIComponent is global function

Just wrap basePath in encodeURIComponent and everything will work

var SOUND_PRESS = new Sound(getSoundName('sound_press'), encodeURIComponent(Sound.MAIN_BUNDLE));

That's right answer. thanks.

Just wrap basePath in encodeURIComponent and everything will work

var SOUND_PRESS = new Sound(getSoundName('sound_press'), encodeURIComponent(Sound.MAIN_BUNDLE));

Thanks @vacoo I've been stuck on this for a long time.

Handling both android and ios:

import { Platform } from 'react-native';
import Sound from 'react-native-sound';

const mainBundle = Platform.OS === 'ios'
  ? encodeURIComponent(Sound.MAIN_BUNDLE)
  : Sound.MAIN_BUNDLE;

export const notifAlert = new Sound('notif_alert.mp3', mainBundle, error => {
  if (error) console.error(error);
});
Was this page helpful?
0 / 5 - 0 ratings