If I preload multiple sounds, everytime I try to play one, the last preloaded sound is played
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.
This happens with React Native Assets (require('./audio.mp3')), what I've found is that djb2Code function always return 5381 for all asset files.
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.
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.
me to
I was also having same problem with 0.10.5 when using require, but seems to work fine with 0.10.9
@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.