zmxv / react-native-sound

React Native module for playing sound clips
MIT License
2.79k stars 749 forks source link

failed to load the sound {"code": "ENSOSSTATUSERRORDOMAIN-10875", "domain": "NSOSStatusErrorDomain", "message": "The operation couldn’t be completed. (OSStatus error -10875.) #799

Open jinglongbu opened 2 years ago

jinglongbu commented 2 years ago

in iOS,when the resources path is local file it work ,but when is the link as https://abc.mp3,it can not work and err is

{"code": "ENSOSSTATUSERRORDOMAIN-10875", "domain": "NSOSStatusErrorDomain", "message": "The operation couldn’t be completed. (OSStatus error -10875.)", "nativeStackIOS": ["0 rndemo 0x000000010298fe0c RCTJSErrorFromCodeMessageAndNSError + 116", "1 rndemo 0x000000010298fd58 RCTJSErrorFromNSError + 256", "2 rndemo 0x000000010285c828 -[RNSound prepare:withKey:withOptions:withCallback:] + 1368", "3 CoreFoundation 0x00000001ab5cbfc4 7769FFAC-4FCD-332D-A4BE-DA2F0E2FFEA5 + 1277892", "4 CoreFoundation 0x00000001ab4957d0 7769FFAC-4FCD-332D-A4BE-DA2F0E2FFEA5 + 6096", "5 CoreFoundation 0x00000001ab4963f0 7769FFAC-4FCD-332D-A4BE-DA2F0E2FFEA5 + 9200", "6 rndemo 0x00000001029283e0 -[RCTModuleMethod invokeWithBridge:module:arguments:] + 1828", "7 rndemo 0x000000010292bf1c _ZN8facebook5reactL11invokeInnerEP9RCTBridgeP13RCTModuleDatajRKN5folly7dynamicEiN12_GLOBAL__N_117SchedulingContextE + 1156", "8 rndemo 0x000000010292b8bc _ZZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEiENK3$_0clEv + 144", "9 rndemo 0x000000010292b820 ___ZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEi_block_invoke + 28", "10 libdispatch.dylib 0x00000001ab266134 E749B178-A64D-3363-83EF-863A6073A06B + 8500", "11 libdispatch.dylib 0x00000001ab2675ac E749B178-A64D-3363-83EF-863A6073A06B + 13740", "12 libdispatch.dylib 0x00000001ab26da64 E749B178-A64D-3363-83EF-863A6073A06B + 39524", "13 libdispatch.dylib 0x00000001ab26e498 E749B178-A64D-3363-83EF-863A6073A06B + 42136", "14 libdispatch.dylib 0x00000001ab277a5c E749B178-A64D-3363-83EF-863A6073A06B + 80476", "15 libsystem_pthread.dylib 0x00000001ab2cd718 _pthread_wqthread + 276", "16 libsystem_pthread.dylib 0x00000001ab2d39c8 start_wqthread + 8"], "userInfo": {}}

in android whatever path is local file or link They can all work

this is my code

`let url = 'https://test.com/art01.mp3'; let musciPath = require('@src/resources/art01.mp3'); let music = new Sound( url,'', (error) => { console.log(66665); if (error) { console.log('failed to load the sound', error); // Alert.alert('Notice', 'audio file error. (Error code : 1)');

} else {
    music.play()

}

});` can someone help me? thanks very much

qtipee commented 2 years ago

I have the same problem, except it is not working with audio files from Firebase Storage. I can play sounds from URL with other domains. NSAllowsArbitraryLoads is set to true.

Coffeegerm commented 2 years ago

Same issue, been digging into the native code and the player is most likely getting passed nil data for initilization and thats where the error is being throwm, how to solve this? Not sure yet, but have been taking a look for a bit now and it's blocking a feature for us here

esteban199 commented 2 years ago

same issue here

qtipee commented 2 years ago

Same issue, been digging into the native code and the player is most likely getting passed nil data for initilization and thats where the error is being throwm, how to solve this? Not sure yet, but have been taking a look for a bit now and it's blocking a feature for us here

Are you using Firebase? Because my guess is that the iOS audio player component cannot load URLs containing characters like %2F, which are parts of Firebase Storage URLs.

lmarques6 commented 2 years ago

See my comment here, if the above comment is true, you may have to undo the encoding on the url

ArjunKarki commented 2 years ago

I still can't play url from firebase ?

chandu-abhi commented 1 year ago

Yes storage links will not work in IOS, but you can use "React-native-blob-utils", using this lib, pass storage url and download that file locally and pass that locally downloaded path to sound library. that will work.

ghost commented 1 year ago

You can make audioPath => decodeURI(audioPath) and Sound.MAIN_BUNDLE into "" (empty string) for IOS

jogyfelix commented 1 year ago

navigate to the RNSound package in your project's node_modules folder and open the RNSound.m file. Look for the following lines of code:

fileNameUrl = [NSURL URLWithString:fileNameEscaped];

replace it with

fileNameUrl = [NSURL URLWithString:fileName];

This modification will remove the URL encoding from the file name and should allow React Native Sound to load the audio file from Firebase storage without encountering the OSStatus error.

therealtgd commented 1 year ago

navigate to the RNSound package in your project's node_modules folder and open the RNSound.m file. Look for the following lines of code:

fileNameUrl = [NSURL URLWithString:fileNameEscaped];

replace it with

fileNameUrl = [NSURL URLWithString:fileName];

This modification will remove the URL encoding from the file name and should allow React Native Sound to load the audio file from Firebase storage without encountering the OSStatus error.

This is okay but not ideal, the library should be updated with the fix so we are not required to edit the files in node_modules.

YauhenBichel commented 8 months ago

Patch file with changes from @jogyfelix and @therealtgd for react-native-sound 0.11.2

react-native-sound+0.11.2.patch

VatsalJainLobb commented 2 months ago

This Works for me: Try removing the encoding from the remote url for IOS before using to create Sound Instance. Here is code snippet:

            let soundUrl = url;
            if (Platform.OS === 'ios') {
                soundUrl = decodeURIComponent(url);
            }
            const soundInstance = new Sound(soundUrl, '', (error) => {
                if (error) {
                    return;
                }
                setDuration(soundInstance.getDuration())
                setSound(soundInstance);
            });