More workarounds for devices that crash when getting a cast context (#6378)

This commit is contained in:
ByteHamster 2023-03-14 19:56:23 +01:00 committed by GitHub
parent 870fe2be56
commit 07b59d8b32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 6 deletions

View File

@ -59,11 +59,14 @@ public class CastPsmp extends PlaybackServiceMediaPlayer {
if (GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context) != ConnectionResult.SUCCESS) {
return null;
}
if (CastContext.getSharedInstance(context).getCastState() == CastState.CONNECTED) {
return new CastPsmp(context, callback);
} else {
return null;
try {
if (CastContext.getSharedInstance(context).getCastState() == CastState.CONNECTED) {
return new CastPsmp(context, callback);
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public CastPsmp(@NonNull Context context, @NonNull PSMPCallback callback) {

View File

@ -16,8 +16,15 @@ public class CastStateListener implements SessionManagerListener<CastSession> {
castContext = null;
return;
}
castContext = CastContext.getSharedInstance(context);
castContext.getSessionManager().addSessionManagerListener(this, CastSession.class);
CastContext castCtx;
try {
castCtx = CastContext.getSharedInstance(context);
castCtx.getSessionManager().addSessionManagerListener(this, CastSession.class);
} catch (Exception e) {
e.printStackTrace();
castCtx = null;
}
castContext = castCtx;
}
public void destroy() {