qiuxiang/react-native-recording

Recorder cannot record more than 1 time if audio is played after recording (iOS)

speggos opened this issue · 2 comments

Hello, first of all thank you for the wonderful library! I am making an app which needs DSP and this has been such a life saver.

I'm having an issue with the recorder. Here is a high level of what the app is should be doing:

  1. Record audio
  2. Play a sound
  3. Record audio again

In step 3, I am getting nothing sent to the recorder's event listener (specifically, one empty buffer ( [] ) upon starting recording, and another upon ending recording)

Here is my code:

Starting Recording:

this.Recorder = require('react-native-recording').default;

        this.Recorder.init({
            bufferSize: constants.bufferSize,
            sampleRate: constants.sampleRate,
            bitsPerChannel: constants.bitsPerChannel,
            channelsPerFrame: constants.channelsPerFrame,
        });

        this.Listener = this.Recorder.addRecordingEventListener((data) => {
        	console.log('New data!', data.length)
        });

		this.Recorder.start();

Stopping recording:

this.Recorder.stop();
this.Recorder = null;
this.Listener.remove();
this.Listener = null;

Playing the sound (happens after stopRecording() )

let sound = new Player(soundTypeFiles[soundType], {autoDestroy: true});
sound.volume = 0.5;
sound.play(sound.destroy());

The first run of recording returns buffers as expected. The sound plays as expected. However, when I try to record audio again, here is my console:

  1. Start recording
    New data!, 0
    ...nothing

  2. Stop recording
    New data!, 0

This is fully functional on android, and I'm not sure what to do on this issue. Any help is appreciated :)

recordStart = () => {
   	this.Listener = this.Recorder.addRecordingEventListener((data) => {
       	console.log('New data!', data.length)
       });
   	Recording.start()

   }

	recordStop = () => {
		this.listener.remove();

	}

I fixed it with the code. (you should remove this.listener from inside of componentDidMount )

Fixed this by playing audio using a different method ('MultiRoute'), do not know what was causing the issue on a low level, must be something to do with resources not being released.

This can be closed, thank you!