ryanheise / just_audio

Audio Player
1.05k stars 676 forks source link

Android OutOfMemoryError When Using setAudioSource with Large Audio File (3GB, 56 Hours) #1235

Closed Mc231 closed 6 months ago

Mc231 commented 6 months ago

Which API doesn't behave as documented, and how does it misbehave?

The setAudioSource method does not handle large audio files as expected on Android devices. When attempting to use setAudioSource(AudioSource.file(filePath)) with a very large audio file (approximately 3GB in size and 56 hours in duration), it results in an OutOfMemory error.

Minimal reproduction project Provide a link here using one of two options:

  1. Fork this repository and modify the example to include a large audio file (3GB, 56 hours duration) in the assets or as a local file that the app attempts to load.

To Reproduce (i.e. user steps, not code) Steps to reproduce the behavior:

  1. Clone the official JustAudio repository.
  2. Open the project in Android Studio or another IDE that supports Flutter.
  3. Navigate to the main audio player setup in the example.
  4. Replace the existing audio source ("nature.mp3") with a large file (approx 3GB, 56 hours duration) either by placing it in the assets folder or referencing it as a local file.
  5. Run the application on an Android device.
  6. Attempt to play the large audio file.
  7. Observe that an OutOfMemory error occurs, preventing the audio from being played.

Error messages

E/LoadTask(15763): OutOfMemory error loading stream
E/LoadTask(15763):   java.lang.OutOfMemoryError: Failed to allocate a 69727472 byte allocation with 18247840 free bytes and 17MB until OOM, target footprint 268435456, growth limit 268435456
E/LoadTask(15763):       at com.google.android.exoplayer2.extractor.mp4.Mp4Extractor.calculateAccumulatedSampleSizes(Mp4Extractor.java:807)
E/LoadTask(15763):       at com.google.android.exoplayer2.extractor.mp4.Mp4Extractor.processMoovAtom(Mp4Extractor.java:574)
E/LoadTask(15763):       at com.google.android.exoplayer2.extractor.mp4.Mp4Extractor.processAtomEnded(Mp4Extractor.java:474)
E/LoadTask(15763):       at com.google.android.exoplayer2.extractor.mp4.Mp4Extractor.readAtomPayload(Mp4Extractor.java:456)
E/LoadTask(15763):       at com.google.android.exoplayer2.extractor.mp4.Mp4Extractor.read(Mp4Extractor.java:254)
E/LoadTask(15763):       at com.google.android.exoplayer2.source.BundledExtractorsAdapter.read(BundledExtractorsAdapter.java:127)
E/LoadTask(15763):       at com.google.android.exoplayer2.source.ProgressiveMediaPeriod$ExtractingLoadable.load(ProgressiveMediaPeriod.java:1039)
E/LoadTask(15763):       at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:412)
E/LoadTask(15763):       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
E/LoadTask(15763):       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
E/LoadTask(15763):       at java.lang.Thread.run(Thread.java:1012)
E/ExoPlayerImplInternal(15763): Playback error
E/ExoPlayerImplInternal(15763):   com.google.android.exoplayer2.ExoPlaybackException: Source error
E/ExoPlayerImplInternal(15763):       at com.google.android.exoplayer2.ExoPlayerImplInternal.handleIoException(ExoPlayerImplInternal.java:644)
E/ExoPlayerImplInternal(15763):       at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:620)
E/ExoPlayerImplInternal(15763):       at android.os.Handler.dispatchMessage(Handler.java:103)
E/ExoPlayerImplInternal(15763):       at android.os.Looper.loopOnce(Looper.java:232)
E/ExoPlayerImplInternal(15763):       at android.os.Looper.loop(Looper.java:317)
E/ExoPlayerImplInternal(15763):       at android.os.HandlerThread.run(HandlerThread.java:68)
E/ExoPlayerImplInternal(15763):   Caused by: com.google.android.exoplayer2.upstream.Loader$UnexpectedLoaderException: Unexpected OutOfMemoryError: Failed to allocate a 69727472 byte allocation with 18247840 free bytes and 17MB until OOM, target footprint 268435456, growth limit 268435456
E/ExoPlayerImplInternal(15763):       at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:441)
E/ExoPlayerImplInternal(15763):       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
E/ExoPlayerImplInternal(15763):       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
E/ExoPlayerImplInternal(15763):       at java.lang.Thread.run(Thread.java:1012)
E/ExoPlayerImplInternal(15763):   Caused by: java.lang.OutOfMemoryError: Failed to allocate a 69727472 byte allocation with 18247840 free bytes and 17MB until OOM, target footprint 268435456, growth limit 268435456
E/ExoPlayerImplInternal(15763):       at com.google.android.exoplayer2.extractor.mp4.Mp4Extractor.calculateAccumulatedSampleSizes(Mp4Extractor.java:807)
E/ExoPlayerImplInternal(15763):       at com.google.android.exoplayer2.extractor.mp4.Mp4Extractor.processMoovAtom(Mp4Extractor.java:574)
E/ExoPlayerImplInternal(15763):       at com.google.android.exoplayer2.extractor.mp4.Mp4Extractor.processAtomEnded(Mp4Extractor.java:474)
E/ExoPlayerImplInternal(15763):       at com.google.android.exoplayer2.extractor.mp4.Mp4Extractor.readAtomPayload(Mp4Extractor.java:456)
E/ExoPlayerImplInternal(15763):       at com.google.android.exoplayer2.extractor.mp4.Mp4Extractor.read(Mp4Extractor.java:254)
E/ExoPlayerImplInternal(15763):       at com.google.android.exoplayer2.source.BundledExtractorsAdapter.read(BundledExtractorsAdapter.java:127)
E/ExoPlayerImplInternal(15763):       at com.google.android.exoplayer2.source.ProgressiveMediaPeriod$ExtractingLoadable.load(ProgressiveMediaPeriod.java:1039)
E/ExoPlayerImplInternal(15763):       at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:412)
E/ExoPlayerImplInternal(15763):       ... 3 more
E/AudioPlayer(15763): TYPE_SOURCE: Unexpected OutOfMemoryError: Failed to allocate a 69727472 byte allocation with 18247840 free bytes and 17MB until OOM, target footprint 268435456, growth limit 268435456
I/ExoPlayerImpl(15763): Release c4baab [ExoPlayerLib/2.18.7] [oriole, Pixel 6, Google, 34] [goog.exo.core, goog.exo.exoplayer, goog.exo.decoder, goog.exo.datasource, goog.exo.extractor]
I/ExoPlayerImpl(15763): Init acc7849 [ExoPlayerLib/2.18.7] [oriole, Pixel 6, Google, 34]

Expected behavior Audio should be loaded

Screenshots

Screenshot 2024-04-30 at 16 41 24

Desktop (please complete the following information):

Smartphone (please complete the following information):

Flutter SDK version

[✓] Flutter (Channel stable, 3.19.6, on macOS 14.0 23A344 darwin-arm64, locale en-GB)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2023.2)
[✓] IntelliJ IDEA Community Edition (version 2023.1)
[✓] VS Code (version 1.87.2)
[✓] Connected device (4 available)
[✓] Network resources

• No issues found!

Additional context Add any other context about the problem here.

ryanheise commented 6 months ago

Where is the forked repository?

Mc231 commented 6 months ago

Where is the forked repository?

Thank you for looking into this. There's no need to fork the repository to reproduce the bug; you can use the unmodified example provided in this repository.

ryanheise commented 6 months ago

I'm asking for the fork because the instructions I provided you on submitting a bug report required it. You did not follow those instructions, so I am asking for you to do so. The minimal reproduction project section still makes reference to a "fork" which simply was not provided. If you want to provide an audio file that reproduces the bug, you may also do that. You did neither.

Also, the next section on "To Reproduce (i.e. user steps, not code)" contains instructions for modifying the code which is EXPRESSLY against what the instructions say.

I'm closing this as an invalid issue. I'll reopen it if you fix it and add a comment below to notify that it is done.

github-actions[bot] commented 6 months ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs, or use StackOverflow if you need help with just_audio.