react-native-sound
react-native-sound copied to clipboard
playback failed due to audio decoding errors
[...]
idnPet = null;
componentWillMount(){
this.idnPet = new Sound('idnPet.mp3', '../../audios/', (error) => {
if (error) {
console.log('failed to load the sound', error);
return;
}
// loaded successfully
console.log('duration in seconds: ' + this.idnPet.getDuration() + 'number of channels: ' + this.idnPet.getNumberOfChannels());
});
}
playIdnPet() {
// Play the sound with an onEnd callback
this.idnPet.play((success) => {
if (success) {
console.log('successfully finished playing');
} else {
console.log('playback failed due to audio decoding errors');
// reset the player to its uninitialized state (android only)
// this is the only option to recover after an error occured and use the player again
this.idnPet.reset();
}
});
}
[...]
Can anyone tell me what I'm doing wrong? When I call the function playIdnPet ()
I get this message.
My workspace: https://i.imgur.com/tLYZl0u.png
May be you need change sound files location to main/res/raw/(name sounds)
Any update on this issue?
i have same issue. I did put my sound file into main/res/raw
folder in android
this.idnPet = new Sound('name.mp3', Sound.MAIN_BUNDLE, (error) => {
if (error) {
console.log('failed to load the sound', error);
}
});
Adding the mp3 in android/app/src/main/res/raw It works perfect.
same problem
Solved following this solution from 2016: https://github.com/zmxv/react-native-sound/issues/20#issuecomment-205683378
this.idnPet = new Sound('idnPet.mp3', '../../audios/', (error) => { if (error) { console.log('failed to load the sound', error); return; } **move your playIdnPet function here ** // loaded successfully console.log('duration in seconds: ' + this.idnPet.getDuration() + 'number of channels: ' + this.idnPet.getNumberOfChannels()); });
For some reason, adding the mp3 to the iOS project doesn't do the trick. Could anyone can confirm me the location where the file should reside to use it? Thanks.