Skip to content

SDK fails to resume previously created session with an internal error (code: 2152) #144

@adadukin-dolby

Description

@adadukin-dolby

Cast SDK fails to reconnect with the pre-existing session when using the latest versions of the Cast Framework:

  • specifically, the regression is observed at 22.0.0 and newer,
  • 21.5.0 seems to be the latest working version

Upon reopening the app, the session resumption fails (onSessionResumeFailed triggers) and reports error 2152. The logs look similar to the logs below:

Image

Tip

Demo app: reproduction_app.zip

Setup

Phone: Google Pixel 10

Android version: 16 (CP1A.260505.005)

Google Play Services: 26.19.34 (260400-919740205)

Cast device: I was able to reproduce the issue on all cast devices I have. For instance, Google Cast NC2-6A5

Sample App

I am using slightly modified (to be able to use Cast SDK 22.0.0) official CastVideos-android sample app, working with app-kotlin gradle target (though I believe pretty much similar considerations apply to app-java target as well).

To be able to reproduce the issue the app should be modified in next fashion:

  1. Update Cast Framework in build.gradle
implementation 'com.google.android.gms:play-services-cast-framework:22.0.0'
  1. In the same file update minSdk from 19 to 21 (minimum required for 22.0.0)
minSdkVersion 21
  1. Update Kotlin and JVM targets to compile the app. I used 2.2.21 and 17 versions respectively.

  2. Unfortunately, videos catalogue that is used in the app has been taken down (issue) at the moment of testing, so I also patched the fetching logic.

Go to VideoItemLoader#loadInBackground and change the code to provide the list of video samples

        return try {
            val movieMetadata = MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE)
            movieMetadata.putString(MediaMetadata.KEY_SUBTITLE, "ExoPlayer CastSDK Sample")
            movieMetadata.putString(MediaMetadata.KEY_TITLE, "Testing on Cast Framework 22.0.0")

            return listOf(
                MediaInfo.Builder("https://storage.googleapis.com/exoplayer-test-media-1/mkv/android-screens-lavf-56.36.100-aac-avc-main-1280x720.mkv")
                    .setContentType("video/mp4")
                    .setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
                    .setMetadata(movieMetadata)
                    .build()
            )
        } catch (e: Exception) {
            Log.e(TAG, "Failed to fetch media data", e)
            null
        }

Also, in VideoListAdapter#onBindViewHolder remove the viewHolder#setImage call.

  1. Add logs to VideoBrowserFragment.MySessionManagerListener

  2. Remove MediaTransferReceiver from AndroidManifest.xml as we should not transfer the ownership of the session to the system (otherwise, the session will stop upon the app is closed).

The app is ready for testing.

See debug apk attached as well.

Reproduction steps

  1. Open the cast app
  2. Click on the MediaRouteButton and connect to a cast device
  3. Click on the "Testing on Cast Framework 22.0.0" video item
  4. Click play and wait until the video is played on the cast device
  5. !!! Kill the app and restart it
  6. Nothing happens, after some time you will see the error in logcat
VideoBrowserFragment    com.google.sample.cast.refplayer     D  onSessionResumeFailed: 2152

Expected behaviour

Cast SDK automatically reconnects to the previously existing session.

After creating the session and restarting the app, the logs should look like

VideoBrowserFragment    com.google.sample.cast.refplayer     D  onSessionResumed, wasSuspended=false

Reproduction rate

Please, do keep in mind that the reproduction rate is extremely closed to 100% but not equal to it. From time to time the app works exactly as expected, albeit it happens 2-3 times out of 100 runs.

Similar issues

Similar issues have been reported throughout the last year, though no resolution (except downgrading to 21.5.0) has been found there. Namely,

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions