chore(android): add null checks (#4168)

This commit is contained in:
Krzysztof Moch 2024-09-14 15:20:50 +02:00 committed by GitHub
parent 84a27f3d9f
commit b74cb59602
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 6 deletions

View File

@ -899,17 +899,25 @@ public class ReactExoplayerView extends FrameLayout implements
playbackServiceBinder = (PlaybackServiceBinder) service; playbackServiceBinder = (PlaybackServiceBinder) service;
try { try {
playbackServiceBinder.getService().registerPlayer(player, Activity currentActivity = themedReactContext.getCurrentActivity();
Objects.requireNonNull((Class<Activity>) (themedReactContext.getCurrentActivity()).getClass())); if (currentActivity != null) {
playbackServiceBinder.getService().registerPlayer(player,
(Class<Activity>) currentActivity.getClass());
} else {
// Handle the case where currentActivity is null
DebugLog.w(TAG, "Could not register ExoPlayer: currentActivity is null");
}
} catch (Exception e) { } catch (Exception e) {
DebugLog.e(TAG, "Cloud not register ExoPlayer"); DebugLog.e(TAG, "Could not register ExoPlayer: " + e.getMessage());
} }
} }
@Override @Override
public void onServiceDisconnected(ComponentName name) { public void onServiceDisconnected(ComponentName name) {
try { try {
playbackServiceBinder.getService().unregisterPlayer(player); if (playbackServiceBinder != null) {
playbackServiceBinder.getService().unregisterPlayer(player);
}
} catch (Exception ignored) {} } catch (Exception ignored) {}
playbackServiceBinder = null; playbackServiceBinder = null;
@ -917,7 +925,7 @@ public class ReactExoplayerView extends FrameLayout implements
@Override @Override
public void onNullBinding(ComponentName name) { public void onNullBinding(ComponentName name) {
DebugLog.e(TAG, "Cloud not register ExoPlayer"); DebugLog.e(TAG, "Could not register ExoPlayer");
} }
}; };

View File

@ -121,7 +121,7 @@ class VideoPlaybackService : MediaSessionService() {
} }
private fun buildNotification(session: MediaSession): Notification { 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 flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP
} }