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

Sound not playing after few audio Successfully played (Android)

Open aniketgupta8960 opened this issue 3 years ago • 2 comments

We played some audio on android but after few audio successfully played we get this error code setConfig(0xf25a71a0:google.mp3.decoder, ConfigPriority(0x6f800002)) ERROR: Undefined(0x80001001) getConfig(0xf25a71a0:google.mp3.decoder, ConfigAndroidVendorExtension(0x6f100004)) ERROR: Undefined(0x80001001) After this error no audio is playing until restart the app although app run fine on ios but facing this issue in android after the audio completed we release the audio reference

we can reproduced this bug if we played 10 audio one by one then in some case it produces the bug

Is your issue with...

  • [ ] 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.66.4"
  • iOS:13
  • Android:9

Does the problem occur on...

  • [ ] Simulator
  • [ ] Device

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

  • Device:All android device

wordAudio.current = new Sound(${prepath}${audioPath}, playFromDownload ? DocumentDirectoryPath : postpath, error => { if (error) { console.log('failed to load the sound', error); wordAudio.current?.release(); wordAudio.current = null; return; } setAudioPlaying(true); // Play the sound with an onEnd callback wordAudio.current.play(success => {

    if (success) {
      if (sliderMaxValue == currentVertices.sumOfWordsNo + 1) {
        setAudioPlaying(false);
      }
      wordAudio.current?.release();
      updateLastWordListenedNumber(currentVertices.sumOfWordsNo + 1);
      nextButtonClicked(false);
   
    } else {
      wordAudio?.current?.release();
      console.log('playback failed due to audio decoding errors');
    }
  });
});

Note-play from download will be played from download and rest from install time delivery in android

aniketgupta8960 avatar Jul 16 '22 14:07 aniketgupta8960

I had a similar problem. It seems Android can only handle a few open sound instances. I found this very old comment. From my experience it seems something like that is still the case. I was trying to open about 16 sound instances so the user could select a notification sound from a menu. This worked fine on iOS but many of them wouldn't play on Android. I also had a number of open sound instances in other parts of the app. I cleaned those up and decided that for this sound selection screen I didn't need to have the sounds preloaded. I could load and play them all in one go like this:

    const s = new Sound(fileName, Sound.MAIN_BUNDLE, (err) => {
      if (err) {
        info(`Error creating sound, ${JSON.stringify(err)}`);
      } else {
        info(
          `Created sound from ${fileName}, Loaded ${JSON.stringify(
            s?.isLoaded()
          )}`
        );
        s.setNumberOfLoops(0)
          .setVolume(Math.pow(volume, 3))
          .play((success) => {
            if (success) {
              info(`Success playing ${fileName}`);
            } else {
              info(`Failed playing ${fileName}`);
            }
            // Sometimes very short sounds (~100ms) don't play
            // if another sound is not playing or has not played in the last second or so.
            // Delaying the release fixes this.
            // Apparently this callback is called before the sound actually starts playing.
            setTimeout(function () {
              info(`Releasing ${s?._filename}`);
              s?.release();
            }, 140);
          });
      }
    });

I had expected there to be a long delay when the user presses the button, but the additional delay from loading seems almost insignificant. The UX is good.

It is important to release your sound instances after using them. Don't use the reset() function. It places the state machine in the End state so the sound instance is no longer useable, but it doesn't release resources. Anyway, when you call release(), the Native code calls reset() before it calls release().

chetstone avatar Jul 29 '22 23:07 chetstone

The solution is there remove the anySoundName.release(); from the code anywhere in the code file.

useEffect(() => { anySoundName.setVolume(1); return () => { anySoundName.release(); // remove this line and see the magic }; }, []);

try first thanks me later :)

waqaskhanroghani avatar Aug 02 '22 09:08 waqaskhanroghani