expo: Unable to stopAndUnloadAsync a recording that just got started
Reproducible Demo
https://snack.expo.io/rJ6j67G6f
After calling await recording.startAsync(), it needs at least ~300ms before recording.stopAndUnloadAsync() can be called, otherwise it’ll fail and subsequent startAsync calls will result in
error: Only one Recording object can be prepared at a given time.
Tested on Android.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 17
- Comments: 15 (2 by maintainers)
For anyone who needs this fix on managed until the SDK 40 release comes out…
I had this issue after getting overly ES6.
vs
This allows
stopAndUnloadAsyncto correctly evaluatethis._canRecord.@Aryk could you tell me more about
ExponentAV.unloadAudioRecorder();?I use
await recordingInstance._cleanupForUnloadedRecorder();and it solves the problem.Hi! I’ve taken a closer look at this and updated the snack to work with SDK 38 and add some additional error handling.
https://snack.expo.io/@ijzerenhein/43e79d
What appears to be going on, is that when
stopAndUnloadAsyncis called too quickly after start, it fails with the errorrecording not stopped. In the snack, if you were to hit “Record” again after that it would throw theOnly one Recording object can be prepared at a given time.error because the previous recording has not been cleaned up correctly.After digging around, it seems that the MediaRecorder class on Android will purposely cause
stopto fail when the recording has not yet received any valid recording data. This article gives a good explanation: https://www.hiren.dev/2017/01/android-media-recorder-stop-failed-1007.htmlSo in short, this behaviour is sort of by design in Android. But unfortunately expo-av is not handling this case or giving an appropriate error. We’ll have a look on how to address this.
@IjzerenHein So I can say this isn’t a bug, but the docs’ example can be improved https://docs.expo.io/versions/latest/sdk/audio/#example-2
I’m still having this issue too. Any solutions? It is something to do with the fact that its all asynchronous
hello guys, I face the same error. Did you solve the error ?
I’m facing this issue too. It says:
Cannot unload a Recording that has not been prepared.