Skip to content

[Android] IndexOutOfBoundsException (Negative Index) during waveform extraction on larger files #45

Description

@EinEinfach

When calling getWaveform or getWaveformBytes on Android with medium to large audio files (e.g., a 5-minute MP3), the process fails with a native index error. This seems to be an integer overflow in the native Android/JNI implementation when calculating byte offsets.
The same file works perfectly on iOS and Web.

Log-Output: I/flutter (16357): Conversion failed: Index -2146671 out of bounds for length 15567358

(Note: The negative index -2146671 strongly suggests a 32-bit integer overflow during offset calculation.)

Environment:
Platform: Android (Tested on Emulator)
OS Version: Android 12+ (API 31+)
Library Version: [0.8.0]
Steps to Reproduce:
Load an MP3 file with a duration of approximately 4-6 minutes.
Call AudioDecoder.getWaveform(path, numberOfSamples: 1000).
The extraction fails with the mentioned IndexOutOfBoundsException.

Expected Behavior:
The waveform should be extracted successfully, regardless of the file length, by using 64-bit integers (long) for byte offset calculations in the native layer.
Workaround:
Currently, the issue can only be avoided by trimming the audio into smaller chunks (e.g., 30-second segments) and extracting them individually, which is highly inefficient.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions