diff options
author | ByteHamster <ByteHamster@users.noreply.github.com> | 2023-03-14 19:56:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-14 19:56:23 +0100 |
commit | 07b59d8b32a43216c0cec01f7bb1f213147db3ef (patch) | |
tree | e00e37b567ae60527879c9557c9546298ffb3517 /playback | |
parent | 870fe2be56ac4ad08432b63b553054a4b8efbf46 (diff) | |
download | AntennaPod-07b59d8b32a43216c0cec01f7bb1f213147db3ef.zip |
More workarounds for devices that crash when getting a cast context (#6378)
Diffstat (limited to 'playback')
-rw-r--r-- | playback/cast/src/play/java/de/danoeh/antennapod/playback/cast/CastPsmp.java | 11 | ||||
-rw-r--r-- | playback/cast/src/play/java/de/danoeh/antennapod/playback/cast/CastStateListener.java | 11 |
2 files changed, 16 insertions, 6 deletions
diff --git a/playback/cast/src/play/java/de/danoeh/antennapod/playback/cast/CastPsmp.java b/playback/cast/src/play/java/de/danoeh/antennapod/playback/cast/CastPsmp.java index 0858d4fc9..c4f135157 100644 --- a/playback/cast/src/play/java/de/danoeh/antennapod/playback/cast/CastPsmp.java +++ b/playback/cast/src/play/java/de/danoeh/antennapod/playback/cast/CastPsmp.java @@ -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) { diff --git a/playback/cast/src/play/java/de/danoeh/antennapod/playback/cast/CastStateListener.java b/playback/cast/src/play/java/de/danoeh/antennapod/playback/cast/CastStateListener.java index 39f54b11c..c9e8c84aa 100644 --- a/playback/cast/src/play/java/de/danoeh/antennapod/playback/cast/CastStateListener.java +++ b/playback/cast/src/play/java/de/danoeh/antennapod/playback/cast/CastStateListener.java @@ -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() { |