In RNSound.m, my AVAudioPlayer errors out because of this line of code:
fileNameUrl = [NSURL URLWithString: [fileName stringByRemovingPercentEncoding]];
if I change it to
fileNameUrl = [NSURL URLWithString: fileName];
it works fine.
However, I'm uncomfortable changing this code. Is there a reason for using stringByRemovingPercentEncoding ? I'm try to play audio from my aws s3 bucket.
Here's the error I'm getting, as outputted on the React debugger JS console:
failed to load the sound
code: "ENSOSSTATUSERRORDOMAIN-10875"
domain: "NSOSStatusErrorDomain"
message: "The operation couldn’t be completed. (OSStatus error -10875.)"
nativeStackIOS:
"0 Broccoli 0x000000010e4d1ff6 RCTJSErrorFromCodeMessageAndNSError + 134"
"1 Broccoli 0x000000010e4d1f23 RCTJSErrorFromNSError + 275"
"2 Broccoli 0x000000010e5993c5 -[RNSound prepare:withKey:withOptions:withCallback:] + 1493"
"3 CoreFoundation 0x0000000110385c6c __invoking___ + 140"
"4 CoreFoundation 0x0000000110385b40 -[NSInvocation invoke] + 320"
"5 CoreFoundation 0x000000011039d956 -[NSInvocation invokeWithTarget:] + 54"
"6 Broccoli 0x000000010e447f13 -[RCTModuleMethod invokeWithBridge:module:arguments:] + 1923"
"7 Broccoli 0x000000010e4a97b3 -[RCTBatchedBridge callNativeModule:method:params:] + 563"
"8 Broccoli 0x000000010e4a8a6e __33-[RCTBatchedBridge handleBuffer:]_block_invoke.477 + 1470"
"9 libdispatch.dylib 0x00000001144c04a6 _dispatch_call_block_and_release + 12"
"10 libdispatch.dylib 0x00000001144e905c _dispatch_client_callout + 8"
"11 libdispatch.dylib 0x00000001144c794f _dispatch_queue_serial_drain + 221"
"12 libdispatch.dylib 0x00000001144c8669 _dispatch_queue_invoke + 1084"
"13 libdispatch.dylib 0x00000001144caec4 _dispatch_root_queue_drain + 634"
"14 libdispatch.dylib 0x00000001144cabef _dispatch_worker_thread3 + 123"
"15 libsystem_pthread.dylib 0x00000001148785a2 _pthread_wqthread + 1299"
"16 libsystem_pthread.dylib 0x000000011487807d start_wqthread + 13"
Here's an example of the type of url I'm trying to use:
Why is this library written to explicitly remove percent encoding on network uris, when NSData seems to require percent encoding?
Local uris also have their percent encoding removed. Though that works, it seems unnecessary, since fileURLWithPath adds percent encoding back on again.
And why is this only in the code for ios, not android? The code for Android reformats local uris (in sound.js) but not network uris.
A side note - [NSData dataWithContentsOfURL:] is deprecated because it's synchronous, and should be replaced with the asynchronous [[[NSURLSession sharedSession] dataTaskWithURL:_ completionHandler:_] resume] .
I agree because this string replacement the module can not play from Firebase Storage Services which uses %2F in file names.
Just ran into this myself. I am also playing URLs from S3 bucket. Thanks for the fix guys. Shame author has not merged this in yet.
Which PR?
Looks like this was fixed in #338.
Most helpful comment
I agree because this string replacement the module can not play from Firebase Storage Services which uses %2F in file names.