zmxv / react-native-sound

React Native module for playing sound clips

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Play function stops working after playing multiple videos

chilliapplegit opened this issue · comments

🪲 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.

🪲 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

🪲 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

🪲 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);
        });
    }
  };

💡 Does the problem have a test case?

💡 Possible solution

💡 Is there a workaround?

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

Is your issue with...

  • iOS
  • Android

Are you using...

  • React Native CLI (e.g. react-native run-android)

Which versions are you using?

  • React Native Sound: "^0.11.2"
  • React Native: "^0.63.5"
  • Android: 13

Does the problem occur on...

  • Simulator
  • Device

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

  • Device:
    Oneplus Nord Android 12