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

Can only play file once

Open juanpasolano opened this issue 9 years ago • 9 comments

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

juanpasolano avatar Jul 26 '16 18:07 juanpasolano

Can you try this workaround?

this.beepOn.play(() => {
  this.beepOn.setCurrentTime(0);
});

sdeleon28 avatar Aug 19 '16 19:08 sdeleon28

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!

MateuszMxxxx avatar Aug 23 '16 08:08 MateuszMxxxx

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

badaz avatar Oct 11 '16 13:10 badaz

Having the same issue here, none of the workarounds work for me

react-native 0.41.0 react-native-sound: 0.9.1

rexlow avatar Mar 10 '17 14:03 rexlow

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

JasonHenson avatar Mar 23 '17 12:03 JasonHenson

cancelSound.setCurrentTime(0).play(); worked for me for a 2 second sound.

saadqbal avatar Apr 05 '19 16:04 saadqbal

I solved it by removing this.sound.release()

this.sound.play(() => {
  this.sound.stop();
  //this.sound.release();
});

jamesdmurphy51 avatar Jul 03 '21 20:07 jamesdmurphy51

It still happens with the latest version of the lib for audio with small duration (0.085 seconds)

CyxouD avatar Dec 17 '21 11:12 CyxouD

<Button
  onPress={() => {
    soundJoined = new Sound("joined.wav", Sound.MAIN_BUNDLE, (err) => {
      soundJoined?.play();
    }).setVolume(0.1);
  }}
  title="Play"
/>;

This solved my problem

danieldang109 avatar Feb 21 '25 11:02 danieldang109