Skip to content

Conversation

@niklasdahlheimer
Copy link

@niklasdahlheimer niklasdahlheimer commented Jul 1, 2025

🛠 Fix OutOfMemoryError when using setSampleFrom() with large content URIs

We encountered OutOfMemoryError crashes when using setSampleFrom() with large audio files accessed via content:// URIs.

✅ Changes

  • Replaced readBytes() in Context.uriToFile()
    Previously, the entire audio file was read into RAM at once, which caused memory issues.
    We now use InputStream.copyTo() to stream the file to a temp location, significantly reducing memory usage.

  • Improved ContentResolver.getUriExtension(uri)
    File extensions weren’t reliably extracted from content:// URIs.
    The function now:

    • Checks the MIME type and maps it to a file extension.
    • Falls back to reading the filename via OpenableColumns.DISPLAY_NAME if needed.

These changes improve stability and compatibility with large audio files provided by content:// sources.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant