I’ve been following this example to make sound effects upon taking a photo (or reading a bar code).
Here is an excerpt of what I’ve been experimenting…
constructor(props) {
super(props);
this.state = {
sound: new Expo.Audio.Sound(),
}
}
//
async componentWillMount() {
await this.state.sound.loadAsync(require('./assets/blah.mp3'));
}
//
_handleBarCodeRead = async(val) => {
try {
await this.state.sound.playAsync(); //This works, but just only once!
}
catch (error) {
//
}
}
Once _handleBarCodeRead
is called, blah.mp3
is played as expected.
However, when I have _handleBarCodeRead
called again, this sound is not played.
(In order to repeat the sound, I have to go to another component and come back to this component)
How do we play a loaded sound resource multiple times without changing views?
Any advice will be appreciated.