You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Android : await recorderController.stop(); sometimes never completes #470
Describe the bug
Since i have upgraded to 2.0.1 version, i have noticed (reproductible) that for audio recordings, when i call String? path = await recorderController.stop(); i don't see the log that is right after and the wave is not generated like frozen.
This only happens on Android, iOS works fine with the same code.
To Reproduce
Steps to reproduce the behavior:
Call .record on Android (physical device)
Record an audio for at least 30sec - 1min
Call .stop as above
Print / log the path output
See that this log is never shown
Expected behavior
The method await recorderController.stop(); should complete like on version < 2.0.x on Android
Smartphone (please complete the following information):
Device: Motorola
OS: Android
Version : 11
Screenshots
If applicable, add screenshots to help explain your problem.
Additional context
This is reproductible no matter the size of the recording, but i think it's easier to reproduce it when the recording is large > 30 seconds.
I have customers on my live that app that have reported they have this issue with recordings less than 5sec but not all the time. However, more than 30 seconds it's almost 100% that the .stop doesn't complete.
Note : this is not device-specific since i could reproduce it with my Motorola, but my customers have Google Pixel 7, Samsung A51 for example with various Android version (11 - 14 - 15)
Reacted by Nico3652, csongorzih-regens, Balázs Némedi, Yudha Haris Purnama and Ruble
i did this a long time ago but it was on Samsung Galaxy A54 5g a record duration of less than 30 seconds
@DorraY Without a stack trace, it's hard to tell if something beyond what's being addressed in the PR is causing this on your end. Could you please test once the PR gets updated by its author and let us know if it resolves the issue? Your confirmation would be really helpful!
Hit this in production too — here's what's happening in plain terms:
When you call stop(), the plugin tells the audio encoder "wrap up." Normally the encoder replies "done" right away, and #486 fixes a bug where that reply could get stuck. But there's a second problem: sometimes the encoder never gets a chance to reply at all, because recording already stopped feeding it new audio. When that happens, stop() just waits forever for a reply that's never coming.
#508 fixes both: it includes #486's fix, plus a safety timer — if the encoder doesn't reply within a short window (default 500ms, adjustable), the plugin stops waiting and finishes the stop itself.
Workaround until it's merged — point your audio_waveforms dependency at the fix branch:
We hit this independently and traced it to a cause that I don't think has been named yet in this thread, and that neither #486 nor #508 closes: CommonEncoder leaks input buffers, so the codec's input pool drains over the course of a recording.
onInputBufferAvailable stores the index in a single field:
In async mode MediaCodec can hand you several input buffers before you consume any of them. Each callback overwrites the previous index, and every overwritten index is lost — that buffer is never queued back, so it never returns to the pool. The longer the recording, the more of the pool is gone, which lines up with the reports here that >30s reproduces almost every time while short clips only fail sometimes.
The endgame is exactly the symptom @iawaisrana described: by the time signalToStop() runs, currentInputBufferIndex is -1 and no further onInputBufferAvailable is coming (audioRecord.stop() has already run), so EOS is never queued, the muxer never finalizes, and stop() never returns. On the AAC/MPEG-4 path the output file is also left without its moov atom, so even the partial recording is unplayable.
What worked for us was fixing the accounting rather than bounding the wait:
keep every available index in a queue (LinkedList<Int>) instead of one field, and drain it in feedEncoder while there is pending input;
queue EOS as soon as it is safe to — checked from both signalToStop() and onInputBufferAvailable, guarded by a flag so it is queued exactly once — instead of only from the next callback;
create a fresh CommonEncoder per recording, so a session that did hang cannot poison the next one.
Since the fix removes the starvation, we haven't needed a grace-period fallback like the one in #508 — though a bounded fallback is still a reasonable belt-and-braces measure for OEM oddities, and it composes fine with this.
Sharing the analysis rather than a competing PR, since #486 and #508 are already in flight here and the maintainers are best placed to decide the shape. Happy to open one if it would help.
Thanks @victorrss, that analysis was spot on. The single currentInputBufferIndex field was dropping buffers, and #508's grace period was only covering for it: stop() would return, but the recording could be cut short wherever encoding had stalled.
#508 is now updated with a fix for the root cause, along the lines you suggested:
every available input buffer index is kept in a queue and drained together with the pending audio
EOS is queued exactly once, as soon as the backlog drains, rather than waiting for a callback that may never come
a fresh CommonEncoder is created per recording
stop() also joins the recording thread before signalling EOS, so no audio is fed after it
The stopTimeoutMs fallback stays as a belt-and-braces measure for OEM oddities. With the buffer accounting fixed, it shouldn't fire in normal use.
Verified on a physical device with 30s+ recordings, back-to-back recordings, pause then stop, and short clips. stop() returned every time and the files played through to the end.
If you're already on the fix branch, run flutter pub upgrade audio_waveforms to pick up the new commit:
If you still hit a hang, logcat with the tag audio_waveforms would help. In particular, check whether Encoder did not finish within the grace period shows up.
Activity
Tom3652 commentedon Jan 7, 2026
Here is how we record maybe this has an impact :
On Android.
ujas-m-simformsolutions commentedon Jan 8, 2026
Thanks for reporting this issue. We can reproduce this issue.
mostafasany commentedon Jan 18, 2026
Hello, Do you have expected resolution date?
GereyTatarkhanov commentedon Jan 19, 2026
I have same problem
AmrTawfek commentedon Jan 22, 2026
Same Issue
mzubairr999 commentedon Jan 22, 2026
@ujas-m-simformsolutions kindly fix this issue it effecting much
even recorder is paused and call stop():
it never return path it stuck
hunghuy201280 commentedon Feb 3, 2026
is there any workarounds?
Tom3652 commentedon Feb 15, 2026
i have not found any yet...
Abaxx commentedon Mar 8, 2026
I am having same issue.
Any workaround yet?
DorraY commentedon Apr 9, 2026
Same issue on Galaxy
lavigarg-simform commentedon Jun 23, 2026
Hi @DorraY! Thanks for testing PR #486 and reporting that you still hit a crash (reference).
To help me track it down, could you share-
That would help a lot in reproducing it on my end. Thanks!
DorraY commentedon Jun 23, 2026
i did this a long time ago
but it was on Samsung Galaxy A54 5g
a record duration of less than 30 seconds
lavigarg-simform commentedon Jun 24, 2026
@DorraY Without a stack trace, it's hard to tell if something beyond what's being addressed in the PR is causing this on your end. Could you please test once the PR gets updated by its author and let us know if it resolves the issue? Your confirmation would be really helpful!
iawaisrana commentedon Aug 4, 2026
Hit this in production too — here's what's happening in plain terms:
When you call
stop(), the plugin tells the audio encoder "wrap up." Normally the encoder replies "done" right away, and #486 fixes a bug where that reply could get stuck. But there's a second problem: sometimes the encoder never gets a chance to reply at all, because recording already stopped feeding it new audio. When that happens,stop()just waits forever for a reply that's never coming.#508 fixes both: it includes #486's fix, plus a safety timer — if the encoder doesn't reply within a short window (default 500ms, adjustable), the plugin stops waiting and finishes the stop itself.
Workaround until it's merged — point your
audio_waveformsdependency at the fix branch:If you want to change how long the safety timer waits, set
stopTimeoutMsonAndroidEncoderSettings:victorrss commentedon Aug 21, 2026
We hit this independently and traced it to a cause that I don't think has been named yet in this thread, and that neither #486 nor #508 closes:
CommonEncoderleaks input buffers, so the codec's input pool drains over the course of a recording.onInputBufferAvailablestores the index in a single field:In async mode MediaCodec can hand you several input buffers before you consume any of them. Each callback overwrites the previous index, and every overwritten index is lost — that buffer is never queued back, so it never returns to the pool. The longer the recording, the more of the pool is gone, which lines up with the reports here that >30s reproduces almost every time while short clips only fail sometimes.
The endgame is exactly the symptom @iawaisrana described: by the time
signalToStop()runs,currentInputBufferIndexis-1and no furtheronInputBufferAvailableis coming (audioRecord.stop()has already run), so EOS is never queued, the muxer never finalizes, andstop()never returns. On the AAC/MPEG-4 path the output file is also left without itsmoovatom, so even the partial recording is unplayable.What worked for us was fixing the accounting rather than bounding the wait:
LinkedList<Int>) instead of one field, and drain it infeedEncoderwhile there is pending input;signalToStop()andonInputBufferAvailable, guarded by a flag so it is queued exactly once — instead of only from the next callback;CommonEncoderper recording, so a session that did hang cannot poison the next one.Since the fix removes the starvation, we haven't needed a grace-period fallback like the one in #508 — though a bounded fallback is still a reasonable belt-and-braces measure for OEM oddities, and it composes fine with this.
Sharing the analysis rather than a competing PR, since #486 and #508 are already in flight here and the maintainers are best placed to decide the shape. Happy to open one if it would help.
fix: stop leaking MediaCodec input buffers in CommonEncoder
docs: add SimformSolutionsPvtLtd#470 fix to CHANGELOG
iawaisrana commentedon Sep 30, 2026
Thanks @victorrss, that analysis was spot on. The single
currentInputBufferIndexfield was dropping buffers, and #508's grace period was only covering for it:stop()would return, but the recording could be cut short wherever encoding had stalled.#508 is now updated with a fix for the root cause, along the lines you suggested:
CommonEncoderis created per recordingstop()also joins the recording thread before signalling EOS, so no audio is fed after itThe
stopTimeoutMsfallback stays as a belt-and-braces measure for OEM oddities. With the buffer accounting fixed, it shouldn't fire in normal use.Verified on a physical device with 30s+ recordings, back-to-back recordings, pause then stop, and short clips.
stop()returned every time and the files played through to the end.If you're already on the fix branch, run
flutter pub upgrade audio_waveformsto pick up the new commit:If you still hit a hang, logcat with the tag
audio_waveformswould help. In particular, check whetherEncoder did not finish within the grace periodshows up.fix: stop leaking MediaCodec input buffers in CommonEncoder
docs: add SimformSolutionsPvtLtd#470 fix to CHANGELOG