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

playback failed due to audio decoding errors

Open rodrigofbm opened this issue 6 years ago • 8 comments

    [...]
    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

rodrigofbm avatar May 23 '18 22:05 rodrigofbm

May be you need change sound files location to main/res/raw/(name sounds)

NguyenPhatBG avatar May 25 '18 04:05 NguyenPhatBG

Any update on this issue?

Narutuffy avatar Sep 08 '18 05:09 Narutuffy

i have same issue. I did put my sound file into main/res/raw folder in android

sinhpn92 avatar Nov 08 '18 11:11 sinhpn92

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.

RoWaiR avatar Dec 19 '18 09:12 RoWaiR

same problem

LouisLeung avatar Dec 31 '18 04:12 LouisLeung

Solved following this solution from 2016: https://github.com/zmxv/react-native-sound/issues/20#issuecomment-205683378

ivanfranchi avatar Apr 24 '19 07:04 ivanfranchi

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()); });

Sayyamabbasi786 avatar Jul 11 '20 07:07 Sayyamabbasi786

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.

acarlstein avatar Nov 01 '23 19:11 acarlstein