Crash in WaveformExtractor’s MediaCodec queueInputBuffer when disposing during waveform extraction
When calling preparePlayer() with shouldExtractWaveform: true on a large audio file (e.g. longer than 10 minutes), if the page is disposed quickly after initialization, a crash occurs in the native layer:
java.lang.IllegalStateException
at android.media.MediaCodec.native_queueInputBuffer(Native Method)
at android.media.MediaCodec.queueInputBuffer(MediaCodec.java:2735)
at com.simform.audio_waveforms.WaveformExtractor$startDecode$1$1.onInputBufferAvailable(WaveformExtractor.kt:72)
It seems the MediaCodec decoder is still running in the background and trying to queue/release buffers after the controller is disposed, which leads to native crashes.
Call preparePlayer(path: ..., shouldExtractWaveform: true) on a relatively large .m4a or .ogg file.
Quickly navigate away or dispose the page (calling dispose() on PlayerController).
After a short delay, the app crashes with IllegalStateException.
Device: e.g. Pixel 6 / Redmi K40
OS: Android 12 / 13
audio_waveforms version: 1.3.0
Flutter version: [your version] (e.g. 3.22.1)
Screenshots If applicable, add screenshots to help explain your problem.
Additional context Add any other context about the problem here.
Currently mechanism to stop extractor isn't released and we might also have to looks if it get correctly disposed when controller is disposed.
During the debugging of the latest version 2.0.2, this issue still occurs when switching pages rapidly.