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 { 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() {