Skip to content

fix #478 by GPT5.2#479

Closed
jesses2025smith wants to merge 1 commit into
SimformSolutionsPvtLtd:mainfrom
jesses2025smith:main
Closed

fix #478 by GPT5.2#479
jesses2025smith wants to merge 1 commit into
SimformSolutionsPvtLtd:mainfrom
jesses2025smith:main

Conversation

@jesses2025smith

Copy link
Copy Markdown

Description

This PR fixes an Android crash during waveform extraction for some MP3 files (notably MP3s with ID3v2.4 tags).
Previously, when MediaCodec decoding failed, WaveformExtractor.stop() could be triggered multiple times (from async codec callbacks / error paths). This led to java.lang.IllegalStateException: codec is released already and a fatal crash on the main thread.

Changes in this PR:

  • Make WaveformExtractor.stop() idempotent (execute stop/release only once) using an atomic guard.
  • Wrap MediaCodec.stop(), MediaCodec.release(), and related cleanup with defensive try/catch to avoid crashing if the codec is already released.
  • Ensure error/exception paths properly stop and clean up resources.
  • Add guards to prevent invalid/zero perSamplePoints from causing premature stop and subsequent callback races.

Motivation:

  • Waveform extraction should never crash the host app; decode failures should be handled gracefully.
  • Verified that disabling waveform extraction avoids the crash (playback remains fine), so the issue is isolated to the extraction pipeline.

Checklist

  • The title of my PR starts with a Conventional Commit prefix (fix:, feat:, docs: etc).
  • I have followed the Contributor Guide when preparing my PR.
  • I have updated/added tests for ALL new/updated/fixed functionality.
  • I have updated/added relevant documentation in docs and added dartdoc comments with ///.
  • I have updated/added relevant examples in examples or docs.

Breaking Change?

  • Yes, this PR is a breaking change.
  • No, this PR is not a breaking change.

Related Issues

Close #478

@jesses2025smith jesses2025smith changed the title fix: fix #478 by GPT5.2 fix #478 by GPT5.2 Jan 28, 2026
@lavigarg-simform

Copy link
Copy Markdown

Keeping this open for the #478 empty-waveform fix

Thanks @jesses2025smith for digging into #478. The diagnosis splits into two separate problems:

  1. The codec is released already crash.
  2. The ID3v2.4 case, where a bad duration sets perSamplePoints to 0 and the waveform comes back empty.

Status of each

Problem Status
Crash Fixed in #495 (lock-based teardown)
Empty waveform Not covered by #495 — the perSamplePoints guard in this PR is what fixes it

We want to keep that guard, so I am leaving this PR open as the fix for the empty-waveform half of #478.

One change before we can merge

This PR also calls stop() (and therefore decoder.stop() / release()) from inside the MediaCodec callbacks. That re-enters the codec on its own callback thread, which can cause an ANR, and it conflicts with the approach in #495.

Could you:

Once that is done we can merge this for #478. Thanks again.

@lavigarg-simform lavigarg-simform added the waiting-for-response Waiting for someone to respond. label Jun 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-for-response Waiting for someone to respond.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crash when extracting waveform for MP3 files with ID3v2.4 tags (MediaCodec "codec is released already")

2 participants