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;
try {
Activity currentActivity = themedReactContext.getCurrentActivity();
if (currentActivity != null) {
playbackServiceBinder.getService().registerPlayer(player,
Objects.requireNonNull((Class<Activity>) (themedReactContext.getCurrentActivity()).getClass()));
(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) {
DebugLog.e(TAG, "Cloud not register ExoPlayer");
DebugLog.e(TAG, "Could not register ExoPlayer: " + e.getMessage());
}
}
@Override
public void onServiceDisconnected(ComponentName name) {
try {
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");
}
};

View File

@ -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
}