react-native-sound icon indicating copy to clipboard operation
react-native-sound copied to clipboard

If I preload multiple sounds, everytime I try to play one, the last preloaded sound is played

Open escobar5 opened this issue 8 years ago • 6 comments

Im preloading my audios like this:


audio = {};

for(let audio in Audio.general) {
      this.sounds[audio] = new SoundManager(Audio.general[audio], (err) => {
        if(err) console.log('Error loading sound ' + audio, err);
        else console.log('Audio ' + audio + ' preloaded');
      });
}

then, I play them like this:

function playSound(audio) {
   this.sounds[audio].play();
}

But whatever I pass to playSound, it always plays the last sound I preloaded.

escobar5 avatar Feb 02 '18 14:02 escobar5

This happens with React Native Assets (require('./audio.mp3')), what I've found is that djb2Code function always return 5381 for all asset files.

escobar5 avatar Feb 02 '18 15:02 escobar5

I'm seeing the same issue, i think the problem must have been introduced between 0.10.4 and 0.10.5.

The fix looks right.

rdy avatar Feb 05 '18 19:02 rdy

I am having this issue only on android. It works fine on ios.

Also, I didn't tried asset files, I only used files from net, downloaded via react-native-fetch-blob with file cache enabled.

alican-k avatar Mar 05 '18 14:03 alican-k

me to

aspidvip avatar Mar 07 '18 04:03 aspidvip

I was also having same problem with 0.10.5 when using require, but seems to work fine with 0.10.9

anton6 avatar Mar 12 '18 20:03 anton6

@anton6 can you please help me with playing audio from cache. I'm using the RNFetchBlob with cache enable. Here is my sample code : -

Sound.setCategory('Playback');

const dirs = RNFetchBlob.fs.dirs;

    RNFetchBlob.config({
      // by adding this option, the temp files will have a file extension
      appendExt: 'mp3',
      fileCache: true,
      path: `${dirs.CacheDir}/audiotrack.mp3`,
    })
      .fetch('GET', 'http://localhost:3000/api/file/download/5c10f72fc360a624da54c426', {
        'x-authorization': ABC',
      })
      .then((res) => {
        const status = res.info();
        // See notes below about preloading sounds within initialization code below.
        const whoosh = new Sound('audiotrack.mp3', Sound.CACHES, (error) => {
          if (error) {
            console.log('failed to load the sound', error);
            return;
          }
          console.log(
            `duration in seconds: ${whoosh.getDuration()}number of channels: ${whoosh.getNumberOfChannels()}`
          );
        });
      })
      // Something went wrong:
      .catch((errorMessage, statusCode) => {
        console.log('errorMessage===> ', errorMessage, " statusCode ", statusCode);
      });

Can you please help me out with this.

imbudhiraja avatar Dec 13 '18 05:12 imbudhiraja