Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
escobar5 opened this issue Feb 2, 2018 · 6 comments · Fixed by #375

Comments

@escobar5
Copy link
Contributor

escobar5 commented Feb 2, 2018

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
Copy link
Contributor Author

escobar5 commented Feb 2, 2018

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 added a commit to escobar5/react-native-sound that referenced this issue Feb 2, 2018
@rdy
Copy link

rdy commented Feb 5, 2018

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.

@alican-k
Copy link

alican-k commented Mar 5, 2018

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.

@aspidvip
Copy link

aspidvip commented Mar 7, 2018

me to

@anton6
Copy link

anton6 commented Mar 12, 2018

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

@imbudhiraja
Copy link

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants