Skip to content

Preload Manager intermittent crash when devices is offline #1568

Closed

Description

@JosephSanjaya

Version

Media3 1.4.0

More version details

No response

Devices that reproduce the issue

Emulator Android running android 11 - 15

Devices that do not reproduce the issue

No response

Reproducible in the demo app?

Yes

Reproduction steps

  • Intermittent
  1. Load any first video
  2. Make devices offline
  3. scroll to second video
  4. Crash

Expected result

When device is offline, video should loaded from memory without any crash

Actual result

Playback crash with following stacktraces:

2024-07-29 10:28:11.206  7605-8770  AndroidRuntime                        E  FATAL EXCEPTION: ExoPlayer:Playback
                                                                                                    Process: com.vidio.android.debug, PID: 7605
                                                                                                    java.lang.IllegalStateException
                                                                                                    	at androidx.media3.common.util.Assertions.checkState(Assertions.java:85)
                                                                                                    	at androidx.media3.exoplayer.upstream.Loader$LoadTask.start(Loader.java:367)
                                                                                                    	at androidx.media3.exoplayer.upstream.Loader$LoadTask.handleMessage(Loader.java:505)
                                                                                                    	at android.os.Handler.dispatchMessage(Handler.java:107)
                                                                                                    	at android.os.Looper.loop(Looper.java:214)
                                                                                                    	at android.os.HandlerThread.run(HandlerThread.java:67)
2024-07-29 10:28:11.230  7605-8770  Uncaught Exception                    E  null
                                                                                                    java.lang.IllegalStateException
                                                                                                    	at androidx.media3.common.util.Assertions.checkState(Assertions.java:85)
                                                                                                    	at androidx.media3.exoplayer.upstream.Loader$LoadTask.start(Loader.java:367)
                                                                                                    	at androidx.media3.exoplayer.upstream.Loader$LoadTask.handleMessage(Loader.java:505)
                                                                                                    	at android.os.Handler.dispatchMessage(Handler.java:107)
                                                                                                    	at android.os.Looper.loop(Looper.java:214)
                                                                                                    	at android.os.HandlerThread.run(HandlerThread.java:67)

Media

Not applicable

Bug Report

Activity

  1. self-assigned this
    on Jul 29, 2024
  2. tianyif commented on Jul 29, 2024

    @tianyif
    Contributor

    Hi @JosephSanjaya,

    Thanks for your feedback on the preload manager! Please allow me to clarify more details:

    • How frequently did see this issue on the demo-shortform app?
    • If you tried DefaultPreloadManager in your app, what preloadLooper did you inject? Is it the same looper that is injected as playbackLooper to the ExoPlayer?

    Looking forward your reply!

  3. JosephSanjaya commented on Aug 1, 2024

    @JosephSanjaya
    Author

    Hi @tianyif , thanks for fast response

    Issue Frequency: I have encountered the issue once in shortform demo, but its really rare in the demo.

    PreloadLooper: In our app, we’re using the same looper for the preload manager as the one injected for the ExoPlayer’s playbackLooper.

    Looking forward to any further insights you might have!

  4. tianyif commented on Aug 5, 2024

    @tianyif
    Contributor

    Hi @JosephSanjaya,

    Thanks for the feedback! Could you please also specify what media (DASH, HLS, and etc.) your app is preloading / playing when you saw this issue?

  5. JosephSanjaya commented on Aug 7, 2024

    @JosephSanjaya
    Author

    Hello @tianyif, we are using HLS media and DASH for DRM Short

  6. tianyif commented on Aug 9, 2024

    @tianyif
    Contributor

    Hi @JosephSanjaya,

    Thanks so much for the precious information!

    When the device is offline, the Loader will be handling the exception thrown from the LoadTask. From the linked code you can see, at L498, it informs the callback on the load error, and then attempts to retry at L505. The callback at L498 varies in implementation for different streams.

    In fact, upon handling message in Loader, we will set the currentTask to null in this finish method, but later onLoadError accidentally sets a new currentTask. We will be looking at all the other stream implementations, and then provide a fix for this issue.

    Thank you again for reporting this issue!

  7. akash1296-dev commented on Aug 13, 2024

    @akash1296-dev

    Hello @tianyif
    Even I am facing the same issue,
    Media3 Version: 1.4.0
    As I open my app, and start preloading media using PreloadMediaSource and I switch off my internet my app crashing with the following crash log:
    FATAL EXCEPTION: playback-thread-collection Process: com.indus.appstore, PID: 2292 java.lang.IllegalStateException at androidx.media3.common.util.Assertions.checkState(Assertions.java:85) at androidx.media3.exoplayer.upstream.Loader$LoadTask.start(Loader.java:367) at androidx.media3.exoplayer.upstream.Loader$LoadTask.handleMessage(Loader.java:505) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:226) at android.os.Looper.loop(Looper.java:313) at android.os.HandlerThread.run(HandlerThread.java:67)

    @tianyif Is there any way to avoid this crash? The number of crashes is increasing, leading to user drop-offs.

  8. tianyif commented on Aug 13, 2024

    @tianyif
    Contributor

    Hi @akash1296-dev,

    I'm working on the fix of this issue and it will be included in the 1.4.1 release. Meanwhile if you hope to avoid the crash I'd suggest you to temporarily rollback your app to the version before adopting 1.4.0, and roll-forward when 1.4.1 is available.

  9. tianyif commented on Aug 14, 2024

    @tianyif
    Contributor

    @JosephSanjaya,

    I pushed a change for fixing the PreloadMediaSource (corresponding to the second sub bullet point in #1568 (comment)), if possible, could you please try this with our development branch main? For the first sub bullet point, I'll still need to discuss with my team to see why it was never seen in the player.

  10. JosephSanjaya commented on Aug 16, 2024

    @JosephSanjaya
    Author

    OKay got it, will check on it

    Thanks! @tianyif

  11. tianyif commented on Aug 28, 2024

    @tianyif
    Contributor

    The fix is with 1.4.1.

    The theory I initially stated was incorrect, however, the real theory is similar. I happened to reproduce this issue and found out the crash was only encountered when loading the HLS media playlist. In such case, MediaPlaylistBundle being the onLoadError callback, and on the path of notifyPlaylistError, it will further call listener.onPlaylistError. HlsMediaPeriod being the listener will further call callback.onContinueLoadingRequested, and then the following story is the same as the previous theory (PreloadMediaSource handles the MediaPeriod.Callback methods synchronously).

    Please note that in such case the returned exclusionFailed will be true as this is an UnknownHostException without an fallback option, so the action will be RETRY, then the Loader will start retry, and here comes this issue that the currentTask is already set from PreloadMediaSource.continueLoading.

    The code paths in the previous theory will not cause this issue because for the SampleStream, its corresponding track will be either excluded and we will "continue loading" another track, then we will not RETRY loading this Loadable, or the track is not able to be excluded and then we RETRY, but in between we are not requesting continueLoading.

    Sorry for being verbose here! Now that the pushed fix should solve the crash, I'm closing this issue, but do let me know if there is anything wrong when trying out 1.4.1.

  12. JosephSanjaya commented on Aug 30, 2024

    @JosephSanjaya
    Author

    Hello @tianyif, we just finished implementing new features using v1.4.1, and its flawless.

    Thank you really much for your effort

  13. locked and limited conversation to collaborators on Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions