React-native-sound: iOS: stringByRemovingPercentEncoding breaks

Created on 13 Jul 2017  Â·  6Comments  Â·  Source: zmxv/react-native-sound

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.

bug ios

Most helpful comment

I agree because this string replacement the module can not play from Firebase Storage Services which uses %2F in file names.

All 6 comments

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:

https://test-broccoli-resources.s3.amazonaws.com/music/p2%2Bp3.mp3?AWSAccessKeyId=FAKEIK342YPJNNRYREAL&Expires=1234567894&Signature=yyY3iQ6FAjNR9p9cwJx0sz4WhBM%3D&x-amz-security-token=AgoGb3JpZ2luENz%2F%2F%2F%2F%2F%2F%2F%2F%2F%2BbEbCXVzLWVhc3QtMSKAAmFiqwroMkkz14jvMMqIY8ma9FupkZlsML1ibsQ6k5%2F7BGSjRMIMp393%2FMHv0L03ALRsh1BUVBiY0hqeEjHCjJIfLyexDGpUdzH%2B%2BQ4oa22hHiywfJfy2Lfwum7VAkMeXoC8JHa%2F07mrSfJlNUDlKpsZiS0Ic%2FKcXBL3LR8wkC59vOXFt2HLgdDs%2FPp5iQJyOYiyfoUFUNppkQS4PbRpYSqX1X44KCDh8uMw80YqG7wYcZVtZa0oTxhJYPcC2ISDQZS5UEw5cFx2YuM1kVW%2BWajbu9Dfj3mDdbMpsBacZs9D1zhc%2F0yRk%2FmxfmNfCEd7ybxRfKCr5xKWC%2B41Frex2mIqpgUIYRAAGgwzNzQ1NzgzMzIxODEiDG2KN3n6asC%2BxdBO0yqDBXkCQsbnI37h%2F2H60S%2F0civ75g0kloOfXOwqUnDECZkHNO0K6ivLJiFY9rWdG4gsIj1ZU6q%2FdsmpYd9UitI%2F9xVPqicl%2FzDDRDmj%2BOeThy3gSA5qWZAO5lse4p3UR43A49AV%2BtYE897wTk0%2FQ5MmP%2BlGZfbhCWKp5VCHHMbPyuyO4RfDg%2FpPDwwLyKjdXsDVz%2BdLgDEgCcpOKZvYgShRci1Zm7Kq8Mn7%2BgeSVI7cGQPi9jNH%2B2EgOtYxcbxM5kWfYkbtFtv29ALwEgyxSDPQF65y6yGJj99yplhDSc5NjSbbFOQ%2FpYdhw%2BwCNBwxa7lA3xl4Del8lZdTyMBN74%2BIlZDPMLIgaqZYgcbw%2Fy8ie9dMxtdj3lKHTjSFx6u91vIS1QGb5UzR7cB6jU%2FRa7PJarcMIgiECwg7vErw0J8oMDWSMAw0sPJrFC2nX1ZUEIzPe%2Fuq%2BB7pnUdqK%2B2x26Bfv3MmGPm5lojrApiQnBEhgEn31RBR%2B7OwwOesHtQkSZHJZZk7nfkh2iw7WfGHltHTY4nSxqOSX9sIjh1rs5OnnvDNSwgz7JhdgsFf5Pwwb3xfMuK2uE9h9bVS%2Fv1ZU0oJ91i6P0l2D80YkBJ4Lgi%2Be8bcThLDPrHrw3IifQJSogVkLA51BqznYBf6E9iJRJRYcZII1%2FFhdKRym0neTW6ixOxKDIBHNmL2ixLlZNkmmoWV8d3w3U0t6azxOWE%2B6AwzlC7jtL9vB0KcBZev42gWTXophqAtk%2FJmTQNpkjsxGDQUtMhIcqdw4dnP2YANEiz%2BIZSWq30nRhTAdLlNlkNZMtWFFiIYRPaQZBmErlMY5J9DEdNRTDKYemCGzjsud8iN3bjIfNIwjui4ywU%3D

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

onepiece-dz picture onepiece-dz  Â·  15Comments

aspitsyn picture aspitsyn  Â·  15Comments

yaronlevi picture yaronlevi  Â·  15Comments

oxilor picture oxilor  Â·  11Comments

pedrobertao picture pedrobertao  Â·  15Comments