zmxv / react-native-sound

React Native module for playing sound clips
MIT License
2.78k stars 747 forks source link

onEnd callback is not fired on Android if setSpeed() #837

Open benhkwoo opened 5 months ago

benhkwoo commented 5 months ago

:beetle: Description

onEnd callback is not fired on Android if setSpeed()

:beetle: What is the observed behavior?

onEnd callback is not fired on Android if setSpeed() before play().

:beetle: Please post your code:

var whoosh = new Sound('whoosh.mp3', Sound.MAIN_BUNDLE, (error) => {
  if (error) {
    console.log('failed to load the sound', error);
    return;
  }

  whoosh.setSpeed(NUMBER)

  whoosh.play((success) => {
  // onEnd callback will not fire if I set speed before play(). It occurs only on Android

    if (success) {
      console.log('successfully finished playing');
    } else {
      console.log('playback failed due to audio decoding errors');
    }
  });
});

Is your issue with...

Are you using...

Which versions are you using?

Does the problem occur on...

If your problem is happening on a device, which device?

Alaaeldin-as1405124 commented 2 weeks ago

I'm having the exact same issue, with setPitch as well

hptung commented 1 week ago

I'm have the same issue too, have you any solutions?

hptung commented 1 week ago

Try this code!!

const play = async (soundInit, callBack, isSlow) => { if (soundInit) { try { Sound.setCategory('Playback');

        if (isSlow)
            soundInit.setSpeed(0.7)
        soundInit.play(callBack);

        if (isSlow && Platform.OS === 'android') {
            setTimeout(() => {
                console.log(soundInit.getDuration())
                callBack()
            }, soundInit.getDuration() * 1000);
        }

    } catch (error) {
        console.log(error);
    }
}

};