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:
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:
- Update Cast Framework in
build.gradle
implementation 'com.google.android.gms:play-services-cast-framework:22.0.0'
- In the same file update
minSdk from 19 to 21 (minimum required for 22.0.0)
-
Update Kotlin and JVM targets to compile the app. I used 2.2.21 and 17 versions respectively.
-
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.
-
Add logs to VideoBrowserFragment.MySessionManagerListener
-
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
- Open the cast app
- Click on the
MediaRouteButton and connect to a cast device
- Click on the "Testing on Cast Framework 22.0.0" video item
- Click play and wait until the video is played on the cast device
- !!! Kill the app and restart it
- 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,
Cast SDK fails to reconnect with the pre-existing session when using the latest versions of the Cast Framework:
22.0.0and newer,21.5.0seems to be the latest working versionUpon reopening the app, the session resumption fails (
onSessionResumeFailedtriggers) and reports error2152. The logs look similar to the logs below: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) officialCastVideos-androidsample app, working withapp-kotlingradle target (though I believe pretty much similar considerations apply toapp-javatarget as well).To be able to reproduce the issue the app should be modified in next fashion:
build.gradleminSdkfrom19to21(minimum required for22.0.0)Update Kotlin and JVM targets to compile the app. I used
2.2.21and17versions respectively.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#loadInBackgroundand change the code to provide the list of video samplesAlso, in
VideoListAdapter#onBindViewHolderremove theviewHolder#setImagecall.Add logs to
VideoBrowserFragment.MySessionManagerListenerRemove
MediaTransferReceiverfromAndroidManifest.xmlas 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.
Tip
Download patch: Cast_SDK_2152_Internal_Error_reproduction_setup.patch
See debug apk attached as well.
Reproduction steps
MediaRouteButtonand connect to a cast deviceTip
See video reproducing on
22.0.0Expected behaviour
Cast SDK automatically reconnects to the previously existing session.
After creating the session and restarting the app, the logs should look like
Tip
See video with expected behaviour on
21.4.0Reproduction 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,