I'm adding the Google Cast SDK to my application. I am testing on nest home mini's, a pixel tab, and chromecasts. Occasionally, I get errors that are not defined in either com.google.android.gms.common.api
's CommonStatusCodes
or com.google.android.gms.cast
's CastStatusCodes
.
Examples: 2152
and 2055
.
They seem to be intermittent, but it would be nice to know what exactly is going on.
applicable code:
private val sessionManagerListener = object : SessionManagerListener<Session> {
override fun onSessionStarted(session: Session, sessionId: String) {
Timber.d("Cast session started with session ID: $sessionId")
}
override fun onSessionEnded(session: Session, error: Int) {
Timber.d("Cast session ended with error code: $error (${getCastStatusCodeMessage(error)})")
}
}
private fun getCastStatusCodeMessage(errorCode: Int): String {
// Try to get the status code string from CastStatusCodes
val castStatusMessage = CastStatusCodes.getStatusCodeString(errorCode)
if (!castStatusMessage.startsWith("unknown status code", ignoreCase = true) &&
!castStatusMessage.startsWith("Unknown cast status code", ignoreCase = true)) {
return castStatusMessage
}
// If not found in CastStatusCodes, try CommonStatusCodes
val commonStatusMessage = CommonStatusCodes.getStatusCodeString(errorCode)
if (!commonStatusMessage.startsWith("unknown status code", ignoreCase = true)) {
return commonStatusMessage
}
// If still not found, return a default message
return "UNKNOWN_CAST_ERROR_CODE: $errorCode"
}