zmxv / react-native-sound

React Native module for playing sound clips
MIT License
2.79k stars 748 forks source link

setNumberLoop(-1) does't work on iOS when mp3 file is short (1s) #640

Open richmonkey opened 4 years ago

richmonkey commented 4 years ago

:beetle: Please post your code:

play(name) {
        console.log("play:" + name);
        Sound.setCategory('Playback');
        // Load the sound file 'whoosh.mp3' from the app bundle
        // See notes below about preloading sounds within initialization code below.
        var whoosh = new Sound(name, Sound.MAIN_BUNDLE, (error) => {
            if (error) {
                console.log('failed to load the sound', error);
            } else { // loaded successfully
                whoosh.setNumberOfLoops(-1);
                whoosh.play((success) => {
                    if (success) {
                        console.log('successfully finished playing');
                    } else {
                        console.log('playback failed due to audio decoding errors');
                    }
                });
            }
        });

    }

Until the problem is fixed, is there a way to work around it? concat the short mp3 file, make the file longer(2s)

:bulb: If the bug is confirmed, would you be willing to create a pull request?

    @synchronized(self) {
        player.delegate = self;
        player.enableRate = YES;
       player.numberOfLoops = -1;//add this, player will loop
        [player prepareToPlay];

Which versions are you using?

Does the problem occur on...

Test file: start.mp3.zip

b2a3e8 commented 4 years ago

I can confirm this issue: actually the sound loops but some of it is cut off after playing correctly the first time.

AnthonyLabaere commented 2 years ago

I confirm too and even without the loop. The begining of the sound is cut off when I try to replay a sound on Android.