Skip to content

TransferCallback.DEFAULT in CastPlayer Doesn't Transferring Correct MediaItems #3199

Closed

Description

@esafirm

Version

Media3 main branch

More version details

We're migrating from our RemoteMediaClient wrapper to media3 CastPlayer. We found out that if the media items is more than 2, it will throw an exception upon disconnecting from the device. Here's the stacktrace:

java.lang.NullPointerException
    at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:902)
    at androidx.media3.exoplayer.source.ProgressiveMediaSource$Factory.createMediaSource(ProgressiveMediaSource.java:297)
    at androidx.media3.exoplayer.source.ProgressiveMediaSource$Factory.createMediaSource(ProgressiveMediaSource.java:86)
    at androidx.media3.exoplayer.ExoPlayerImpl.createMediaSources(ExoPlayerImpl.java:2191)
    at androidx.media3.exoplayer.ExoPlayerImpl.setMediaItems(ExoPlayerImpl.java:627)
    at androidx.media3.common.PlayerTransferState.setToPlayer(PlayerTransferState.java:249)
    at androidx.media3.cast.CastPlayer$TransferCallback.lambda$static$0(CastPlayer.java:66)
    at androidx.media3.cast.CastPlayer$TransferCallback$$ExternalSyntheticLambda0.transferState(D8$$SyntheticClass:0)
    at androidx.media3.cast.CastPlayerImpl.updateActivePlayer(CastPlayerImpl.java:58)
    at androidx.media3.cast.CastPlayerImpl.access$100(CastPlayerImpl.java:32)
    at androidx.media3.cast.CastPlayerImpl$SessionAvailabilityListenerImpl.onCastSessionUnavailable(CastPlayerImpl.java:103)
    at androidx.media3.cast.RemoteCastPlayer.setCastSession(RemoteCastPlayer.java:1651)
    at androidx.media3.cast.RemoteCastPlayer.access$1900(RemoteCastPlayer.java:105)
    at androidx.media3.cast.RemoteCastPlayer$StatusListener.onSessionEnding(RemoteCastPlayer.java:1870)
    at com.google.android.gms.cast.framework.SessionManager.endCurrentSession(SessionManager.java:3)
    at com.bandlab.media.player.impl.LazyCastPlayer.stopCastSession(LazyCastPlayer.kt:95)

After debugging, we found out that the RemoteMediaPlayer.getMediaItemAt(index) can return an invalid/incorrect MediaItem

Image Image

If we play all the items in the playlist, this problem will not happened.

Devices that reproduce the issue

Emulator OS 16

Devices that do not reproduce the issue

No response

Reproducible in the demo app?

Not tested

Reproduction steps

  1. Have playlist with media item count > 3
  2. Connect to Cast Device
  3. Disconnect from Cast Device

Expected result

TransferCallback.DEFAULT or the CastPlayer should handle this internally so the exception will not happen

Actual result

Crashing

Media

Bug Report

Activity

  1. self-assigned this
    on May 11, 2026
  2. tonihei commented on Jun 1, 2026

    @tonihei
    Collaborator

    @AquilesCanta Could you take a look?

  3. AquilesCanta commented on Jun 1, 2026

    @AquilesCanta
    Contributor

    Can you confirm whether you are using the exoplayer receiver app?

  4. jqi26 commented on Jun 2, 2026

    @jqi26

    I'm~seeing a very similar crash while implementing casting in our app using the new CastPlayer.Builder API introduced with 1.9.0. However, I'm having a hard time getting it to consistently happen, seems pretty random. After playing a bunch of media and starting/stopping casting, eventually the app reaches a state where it seems to desync from the cast device. For example playing/pausing in the app stops working, and seeking results in Seek failed. Error code 15: An operation has timed out. in the logs. If you then disconnect then the app crashes with a very similar stack trace to OP.

    No luck replicating in the Exo Cast Demo yet

    Update: Discovered an implementation flaw in our app that adds a duplicate playlist queue when connecting/disconnecting from casting which seems to confuse the casting player, the issue stops happening after fixing that bug. Though maybe it should be caught more gracefully instead of crashing.

  5. esafirm commented on Jun 2, 2026

    @esafirm
    Author

    Can you confirm whether you are using the exoplayer receiver app?

    I haven't check on the demo, but we were casting to Google home speaker. And we don't have custom receiver app.

  6. google-oss-bot commented on Jun 22, 2026

    @google-oss-bot
    Collaborator

    Hey @esafirm. We need more information to resolve this issue but there hasn't been an update in 14 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

    If you have more information that will help us get to the bottom of this, just add a comment!

  7. AquilesCanta commented on Jun 23, 2026

    @AquilesCanta
    Contributor

    And we don't have custom receiver app

    Right, @esafirm, but please share the id. I'm trying to figure out whether you are using the Exoplayer receiver app (id = A12D4273) or the Cast default receiver (id = CC1AD845)

    @tanay187 do you envisage this is the same as internal: b/182255537 ?

  8. esafirm commented on Jun 23, 2026

    @esafirm
    Author

    @AquilesCanta right, I didn't know that the Exoplayer and the cast default receiver are different.

    Our ID is 690ACFE4 , we register it to have our app name on the TV receiver.

    Could you tell me how to get the check what's the receiver implementation for that ID? As of now, I don't have access to the cast app dashboard. Also, I could check if it's also reproduced in the cast default receiver.

  9. tanay187 commented on Aug 19, 2026

    @tanay187
    Contributor

    @esafirm This has been fixed with the commit linked above. Thanks for reporting!

  10. locked and limited conversation to collaborators on Oct 18, 2026
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