React-native-sound: playing sound files with require won't work on react 16 and react native 0.50

Created on 29 Nov 2017  Â·  1Comment  Â·  Source: zmxv/react-native-sound

Saw this in one of my projects and was able to reproduce it in the demo project in this repo:
https://github.com/zmxv/react-native-sound-demo

Playing sounds with require will return an error: OSStatus error 2003334207.

in the demo project set these dependencies in the package.json

    "react": "^16.0.0",
    "react-native": "^0.50",
    "react-native-sound": "^0.10.4"

Build the project and try to play mp3 , aac, or wav via require().

Anyone know a solution that allows for require to continue to be used with react 16 and react native 0.50?

Most helpful comment

this issue only appeared on physical devices, audio worked fine in simulator. I was able to solve this issue by changing line 194 of RNSound.m from:

fileNameUrl = [NSURL fileURLWithPath:[fileName stringByRemovingPercentEncoding]];
to this
fileNameUrl = [NSURL URLWithString: fileName];

When stepping through the code on different versions of react and react native I noticed that the FileName that gets passed into RNSound.m is already in the syntax of a path and doesn't need to be altered at all. So using [NSURL URLWithString : fileName]; solved the issue for me.

"react": "^15.4.2",
 react-native": "^0.41.2",


FileName:
/var/containers/Bundle/Application/DB1F0FC8-C758-42D6-A142-00E3C0CC1266/RNSoundDemo.app/assets/advertising.mp3


FileNameUrl:
file:///var/containers/Bundle/Application/DB1F0FC8-C758-42D6-A142-00E3C0CC1266/RNSoundDemo.app/assets/advertising.mp3




Rn .50
React 16

FileName: 
file:///var/containers/Bundle/Application/2DC412EF-AE3C-4652-B8C8-E4D36415401F/RNSoundDemo.app/assets/advertising.mp3

FileName URL
file:/var/containers/Bundle/Application/2DC412EF-AE3C-4652-B8C8-E4D36415401F/RNSoundDemo.app/assets/advertising.mp3 -- file:///

Error
Error Domain=NSOSStatusErrorDomain Code=2003334207 "(null)"

Sharing in case this helps anyone solve the root of this issue.

>All comments

this issue only appeared on physical devices, audio worked fine in simulator. I was able to solve this issue by changing line 194 of RNSound.m from:

fileNameUrl = [NSURL fileURLWithPath:[fileName stringByRemovingPercentEncoding]];
to this
fileNameUrl = [NSURL URLWithString: fileName];

When stepping through the code on different versions of react and react native I noticed that the FileName that gets passed into RNSound.m is already in the syntax of a path and doesn't need to be altered at all. So using [NSURL URLWithString : fileName]; solved the issue for me.

"react": "^15.4.2",
 react-native": "^0.41.2",


FileName:
/var/containers/Bundle/Application/DB1F0FC8-C758-42D6-A142-00E3C0CC1266/RNSoundDemo.app/assets/advertising.mp3


FileNameUrl:
file:///var/containers/Bundle/Application/DB1F0FC8-C758-42D6-A142-00E3C0CC1266/RNSoundDemo.app/assets/advertising.mp3




Rn .50
React 16

FileName: 
file:///var/containers/Bundle/Application/2DC412EF-AE3C-4652-B8C8-E4D36415401F/RNSoundDemo.app/assets/advertising.mp3

FileName URL
file:/var/containers/Bundle/Application/2DC412EF-AE3C-4652-B8C8-E4D36415401F/RNSoundDemo.app/assets/advertising.mp3 -- file:///

Error
Error Domain=NSOSStatusErrorDomain Code=2003334207 "(null)"

Sharing in case this helps anyone solve the root of this issue.

Was this page helpful?
0 / 5 - 0 ratings