react-native-sound: Sound.MAIN_BUNDLE: undefined - can't find file

I am using Android 5.01 React-native 0.19

after creating object to access my file

const notifySound = new Sound('notify.aac', Sound.MAIN_BUNDLE, (error) => {

I got error { message: 'resource not found', code: -1 } I followed all steps in the documentation, but then console.log - Sound.MAIN_BUNDLE and it’s undefined

{ [Function: Sound]
I/ReactNativeJS( 9413):   enable: [Function],
I/ReactNativeJS( 9413):   MAIN_BUNDLE: undefined,
I/ReactNativeJS( 9413):   DOCUMENT: undefined,
I/ReactNativeJS( 9413):   LIBRARY: undefined,
I/ReactNativeJS( 9413):   CACHES: undefined }

which comes from sound.js file and this code

Sound.MAIN_BUNDLE = RNSound.MainBundlePath;
Sound.DOCUMENT = RNSound.NSDocumentDirectory;
Sound.LIBRARY = RNSound.NSLibraryDirectory;
Sound.CACHES = RNSound.NSCachesDirectory;

Solution In the end, I put my files into android/app/src/main/res/raw, but it would be nice to put this file directly in my service folder

Thanks!

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 17 (5 by maintainers)

Most upvoted comments

For Android I got the same error if I try to reproduce a downloaded file. I got the example working ( putting the audio in /res/raw -> relative path) Everything works fine on IOS (simulator and physical device) if i put reproduce files from Sound.DOCUMENT

For Android i tried DocumentDir/MainBundleDir/DownloadDir but none of these seem to work. Library can’t seem to load the file from these sources. Any idea?

@fritx You’re right. I should probably check if filename is an absolute path in the if condition.

// sound.js
function Sound(filename, basePath, onError) {
  // ...
  if (IsAndroid && !basePath) {
    this._filename = filename.toLowerCase().replace(/\.[^.]+$/, '');  // why?
  }
//  Sound.MAIN_BUNDLE equals to undefined
new Sound('/data/xxx/xx.mp3', Sound.MAIN_BUNDLE)  // does not work
new Sound('/data/xxx/xx.mp3' + '.aaaaa', Sound.MAIN_BUNDLE)  // works
new Sound('/data/xxx/xx.mp3', '/')  // works