Skip to content

Commit 4c8dca5

Browse files
committed
Fixed NPE + Problems with context
1 parent 2f99a21 commit 4c8dca5

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,10 @@ protected void initListeners() {
657657
binding.detailControlsPlayWithKodi.setOnClickListener(this);
658658
if (DEBUG) {
659659
binding.detailControlsCrashThePlayer.setOnClickListener(
660-
v -> VideoDetailPlayerCrasher.onCrashThePlayer(this.player, getLayoutInflater())
660+
v -> VideoDetailPlayerCrasher.onCrashThePlayer(
661+
this.getContext(),
662+
this.player,
663+
getLayoutInflater())
661664
);
662665
}
663666

app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailPlayerCrasher.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import android.widget.Toast;
1111

1212
import androidx.annotation.NonNull;
13+
import androidx.annotation.Nullable;
1314
import androidx.appcompat.app.AlertDialog;
1415

1516
import com.google.android.exoplayer2.C;
@@ -85,9 +86,12 @@ private static Context getThemeWrapperContext(final Context context) {
8586
: R.style.DarkTheme);
8687
}
8788

88-
public static void onCrashThePlayer(final Player player, final LayoutInflater layoutInflater) {
89-
final Context context = player.getContext();
90-
if (!isPlayerAvailable(player)) {
89+
public static void onCrashThePlayer(
90+
@NonNull final Context context,
91+
@Nullable final Player player,
92+
@NonNull final LayoutInflater layoutInflater
93+
) {
94+
if (player == null) {
9195
Log.d(TAG, "Player is not available");
9296
Toast.makeText(context, "Player is not available", Toast.LENGTH_SHORT)
9397
.show();
@@ -152,8 +156,4 @@ private static void tryCrashPlayerWith(
152156
exPlayer);
153157
}
154158
}
155-
156-
private static boolean isPlayerAvailable(final Player player) {
157-
return player != null;
158-
}
159159
}

0 commit comments

Comments
 (0)