Can only play file once
I have a component that loads a sound on constructor function and then plays it on some click handlers.
this.beepOn = new Sound('beep_short_on.wav', Sound.MAIN_BUNDLE, (error) => console.log(error));
However I only hear the sound the first time it this.beepOn.play()
I've even tried stopping it at the end: this.beepOn.play(() => this.beepOn.stop())
Does anyone know why this might be happening.
react-native 0.30.0 react-native-sound: ^0.8.3
Can you try this workaround?
this.beepOn.play(() => {
this.beepOn.setCurrentTime(0);
});
I encountered this problem only with short sounds (less than 3 seconds)
sdeleon28 workaround did great but it required some modification.
sound.setNumberOfLoops(5).play().setCurrentTime(0);
Cheers!
Same problem here with a very short sound but none of the workarounds work for me
react-native 0.33.0 react-native-sound: 0.8.4
Having the same issue here, none of the workarounds work for me
react-native 0.41.0 react-native-sound: 0.9.1
I ended up just recreating the sound object every time I play my short sounds (like in the demo link below). Not sure how efficient/inefficient it is but it did work for me.
this.playSoundBundle is the method i am referring to. https://github.com/zmxv/react-native-sound-demo/blob/master/main.js
cancelSound.setCurrentTime(0).play();
worked for me for a 2 second sound.
I solved it by removing this.sound.release()
this.sound.play(() => {
this.sound.stop();
//this.sound.release();
});
It still happens with the latest version of the lib for audio with small duration (0.085 seconds)
<Button
onPress={() => {
soundJoined = new Sound("joined.wav", Sound.MAIN_BUNDLE, (err) => {
soundJoined?.play();
}).setVolume(0.1);
}}
title="Play"
/>;
This solved my problem