zmxv / react-native-sound

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

Play function stops working after playing multiple videos #825

Open chilliapplegit opened 1 year ago

chilliapplegit commented 1 year ago

:beetle: Description

I have a audio tour player which plays multiple audios based on different Components, The players works perfectly for sometimes nearly 13-15 times it works properly after that, the player breaks down.

:beetle: What is the observed behavior?

The callback for play function (enEnd) gets executed without the audio being played. no actual sounds gets played but the play functions callback occurs and provide true value

:beetle: What is the expected behavior?

it should play the audio first and post aying it fully then only it should be proiding the outcome of true or false in callback value

:beetle: Please post your code:

const fetchAudiofile = async () => {
    if (currentTour?.data?.advancedSettings.assets?.audio?.name) {
      await Database.getStoredAsset(
        assetPath,
        currentTour.data.advancedSettings.assets.audio.name
      )
        .then((imageURL) => {
          const dataReceived = new Sound(imageURL, "", (error) => {
            if (error) {
              console.log("failed to load the sound", error);
              return;
            }
            setIsPlaying(true);
            setIsFinished(false);

            console.log(
              `duration in seconds: ${dataReceived.getDuration()}number of channels: ${dataReceived.getNumberOfChannels()}`
            );

            setAudioPlayer(dataReceived);

            dataReceived.play((success) => {
              if (success) {
                switch (currentTour.data.advancedSettings.choice_type) {
                  case "choice_single":
                  case "choice_double": {
                    setIsPlaying(false);
                    setIsFinished(true);
                    console.log(
                      "Successfully loaded ADHomeScreen with new audio file :>> "
                    );
                    break;
                  }
                  case "instruction":
                  default: {
                    playPauseAudioAction("stop");
                    loadNextTour(
                      currentTour.data.advancedSettings.listItems[0].link
                    );
                    setAudioPlayer(null);
                    break;
                  }
                }
              } else {
                console.log(
                  "Error loading ADHomeScreen with new audio file :>> "
                );
              }
            });
          });
        })
        .catch((e) => {
          console.log("error with List image: ", e);
        });
    }
  };

:bulb: Does the problem have a test case?

:bulb: **Possible solution**

:bulb: Is there a workaround?

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

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?

kukadiyaAni commented 10 months ago

Same issue for me, any solutions?