androidx / media

Jetpack Media3 support libraries for media use cases, including ExoPlayer, an extensible media player for Android
https://developer.android.com/media/media3
Apache License 2.0
1.75k stars 418 forks source link

CastPlayer crashes when Receiver has error in LOAD message interceptor #708

Open JonWatson opened 1 year ago

JonWatson commented 1 year ago

Version

Media3 1.1.1

More version details

When our Cast Receiver has an internal exception/error inside a LOAD message interceptor, the CastPlayer on the Sender app is crashing like so:

// Cast Receiver error, unsure if this is helpful.  This is our bug that needs to be fixed
playerManager.setMessageInterceptor(
  cast.framework.messages.MessageType.LOAD,
  request => {
      // do something bad here that causes an exception in the JavaScript
  }
);

// Cast Sender crashes here
java.lang.IllegalStateException
    at androidx.media3.common.util.Assertions.checkStateNotNull(Assertions.java:117)
    at androidx.media3.cast.CastTimelineTracker.getCastTimeline(CastTimelineTracker.java:113)
    at androidx.media3.cast.CastPlayer.updateTimeline(CastPlayer.java:1031)
    at androidx.media3.cast.CastPlayer.updateTimelineAndNotifyIfChanged(CastPlayer.java:956)
    at androidx.media3.cast.CastPlayer.updateInternalStateAndNotifyIfChanged(CastPlayer.java:832)
    at androidx.media3.cast.CastPlayer.access$800(CastPlayer.java:84)
    at androidx.media3.cast.CastPlayer$StatusListener.onStatusUpdated(CastPlayer.java:1370)
    at com.google.android.gms.cast.framework.media.zzbn.zzm(com.google.android.gms:play-services-cast-framework@@21.3.0:6)
    at com.google.android.gms.cast.internal.zzaq.zzY(com.google.android.gms:play-services-cast@@21.3.0:1)
    at com.google.android.gms.cast.internal.zzaq.zzO(com.google.android.gms:play-services-cast@@21.3.0:59)
    at com.google.android.gms.cast.framework.media.RemoteMediaClient.onMessageReceived(com.google.android.gms:play-services-cast-framework@@21.3.0:1)
    at com.google.android.gms.cast.zzbq.run(com.google.android.gms:play-services-cast@@21.3.0:4)
    at android.os.Handler.handleCallback(Handler.java:942)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:201)
    at android.os.Looper.loop(Looper.java:288)
    at android.app.ActivityThread.main(ActivityThread.java:7918)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

Devices that reproduce the issue

Pixel 7 Pro running Android 13

Devices that do not reproduce the issue

No response

Reproducible in the demo app?

Not tested

Reproduction steps

Have a Cast Receiver that throws an exception within its LOAD messageInterceptor

Expected result

Cast Sender (CastPlayer) should not crash the app

Actual result

CastPlayer crashes the app on a borked timeline

Media

Any

Bug Report

marcbaechinger commented 1 year ago

Thanks for reporting.

If there is no media info object in the media status, we can't really build a timeline. So at this place we probably should just return an empty timeline when mediaStatus.getMediaInfo() is null. This avoids the crash you report.

I wonder whether we can make CastPlayer throw a playback error in such a case.

We look into this an update this issue when we publish a fix for this.