[go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preload Manager intermittent crash when devices is offline #1568

Closed
1 task
JosephSanjaya opened this issue Jul 29, 2024 · 11 comments
Closed
1 task

Preload Manager intermittent crash when devices is offline #1568

JosephSanjaya opened this issue Jul 29, 2024 · 11 comments
Assignees
Labels

Comments

@JosephSanjaya
Copy link

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

@tianyif
Copy link
Contributor
tianyif commented Jul 29, 2024

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!

@JosephSanjaya
Copy link
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!

@tianyif
Copy link
Contributor
tianyif commented Aug 5, 2024

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?

@JosephSanjaya
Copy link
Author

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

@tianyif
Copy link
Contributor
tianyif commented Aug 9, 2024

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!

@akash1296-dev
Copy link

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.

@tianyif
Copy link
Contributor
tianyif commented Aug 13, 2024

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.

copybara-service bot pushed a commit that referenced this issue Aug 13, 2024
When there is an exception thrown from the `LoadTask`, the `Loader` will call `Loader.Callback.onLoadError`. Some implementations of `onLoadError` method may call `MediaPeriod.onContinueLoadingRequested`, and in the `PreloadMediaSource`, its `PreloadMediaPeriodCallback` will be triggered and then it can further call `continueLoading` if it finds needed. However the above process is currently done synchronously, which will cause problem. By calling `continueLoading`, the `Loader` is set with a `currentTask`, and when that long sync logic in `Loader.Callback.onLoadError` ends, the `Loader` will immediately retry, and then a non-null `currentTask` will cause the `IllegalStateException`.

Issue: #1568

#cherrypick

PiperOrigin-RevId: 662550622
@tianyif
Copy link
Contributor
tianyif commented Aug 14, 2024

@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.

colinkho pushed a commit to colinkho/media that referenced this issue Aug 15, 2024
When there is an exception thrown from the `LoadTask`, the `Loader` will call `Loader.Callback.onLoadError`. Some implementations of `onLoadError` method may call `MediaPeriod.onContinueLoadingRequested`, and in the `PreloadMediaSource`, its `PreloadMediaPeriodCallback` will be triggered and then it can further call `continueLoading` if it finds needed. However the above process is currently done synchronously, which will cause problem. By calling `continueLoading`, the `Loader` is set with a `currentTask`, and when that long sync logic in `Loader.Callback.onLoadError` ends, the `Loader` will immediately retry, and then a non-null `currentTask` will cause the `IllegalStateException`.

Issue: androidx#1568

#cherrypick

PiperOrigin-RevId: 662550622
@JosephSanjaya
Copy link
Author

OKay got it, will check on it

Thanks! @tianyif

tianyif added a commit that referenced this issue Aug 22, 2024
When there is an exception thrown from the `LoadTask`, the `Loader` will call `Loader.Callback.onLoadError`. Some implementations of `onLoadError` method may call `MediaPeriod.onContinueLoadingRequested`, and in the `PreloadMediaSource`, its `PreloadMediaPeriodCallback` will be triggered and then it can further call `continueLoading` if it finds needed. However the above process is currently done synchronously, which will cause problem. By calling `continueLoading`, the `Loader` is set with a `currentTask`, and when that long sync logic in `Loader.Callback.onLoadError` ends, the `Loader` will immediately retry, and then a non-null `currentTask` will cause the `IllegalStateException`.

Issue: #1568

PiperOrigin-RevId: 662550622
(cherry picked from commit cd532c5)
@tianyif
Copy link
Contributor
tianyif commented Aug 28, 2024

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.

@tianyif tianyif closed this as completed Aug 28, 2024
@JosephSanjaya
Copy link
Author

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

Thank you really much for your effort

@androidx androidx locked and limited conversation to collaborators Oct 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants