Limiting recording duration with Audio recorder

Hey Expo team! I’m new to Expo and working on my first project where I’d like to incorporate the ability to record audio, but cap the recording duration at 30 seconds. Your audio-recording-example on GitHub has been extremely helpful, however, I’m having a hard time getting stopAndUnloadAsync( ) to call after 30 seconds. Using your example, where would I insert something like:

if (this.state.recordingDuration == 30000) {
this.recording.stopAndUnloadAsync()
};

Maybe I’m way off base here, but can you help me out?

One idea:

Make a recursive function that calls itself every 1 second with setTimeout, then when it hits 30, you call the stopAndUnloadAsync function.

You don’t need to use setTimeout, use the setOnRecordingStatusUpdate method to keep track of the length of the audio as it’s being recorded.