diff --git a/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java b/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java index d00945bc..86e6e3d2 100644 --- a/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -899,17 +899,25 @@ public class ReactExoplayerView extends FrameLayout implements playbackServiceBinder = (PlaybackServiceBinder) service; try { - playbackServiceBinder.getService().registerPlayer(player, - Objects.requireNonNull((Class) (themedReactContext.getCurrentActivity()).getClass())); + Activity currentActivity = themedReactContext.getCurrentActivity(); + if (currentActivity != null) { + playbackServiceBinder.getService().registerPlayer(player, + (Class) currentActivity.getClass()); + } else { + // Handle the case where currentActivity is null + DebugLog.w(TAG, "Could not register ExoPlayer: currentActivity is null"); + } } catch (Exception e) { - DebugLog.e(TAG, "Cloud not register ExoPlayer"); + DebugLog.e(TAG, "Could not register ExoPlayer: " + e.getMessage()); } } @Override public void onServiceDisconnected(ComponentName name) { try { - playbackServiceBinder.getService().unregisterPlayer(player); + if (playbackServiceBinder != null) { + playbackServiceBinder.getService().unregisterPlayer(player); + } } catch (Exception ignored) {} playbackServiceBinder = null; @@ -917,7 +925,7 @@ public class ReactExoplayerView extends FrameLayout implements @Override public void onNullBinding(ComponentName name) { - DebugLog.e(TAG, "Cloud not register ExoPlayer"); + DebugLog.e(TAG, "Could not register ExoPlayer"); } }; diff --git a/android/src/main/java/com/brentvatne/exoplayer/VideoPlaybackService.kt b/android/src/main/java/com/brentvatne/exoplayer/VideoPlaybackService.kt index 6cf6f7d2..77bd4eaf 100644 --- a/android/src/main/java/com/brentvatne/exoplayer/VideoPlaybackService.kt +++ b/android/src/main/java/com/brentvatne/exoplayer/VideoPlaybackService.kt @@ -121,7 +121,7 @@ class VideoPlaybackService : MediaSessionService() { } private fun buildNotification(session: MediaSession): Notification { - val returnToPlayer = Intent(this, sourceActivity).apply { + val returnToPlayer = Intent(this, sourceActivity ?: this.javaClass).apply { flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP }