1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-23 08:30:44 +00:00

Fixed NPE + Problems with context

This commit is contained in:
litetex 2021-11-28 13:42:26 +01:00
parent 2f99a217c3
commit 4c8dca5300
2 changed files with 11 additions and 8 deletions

View File

@ -657,7 +657,10 @@ public final class VideoDetailFragment
binding.detailControlsPlayWithKodi.setOnClickListener(this); binding.detailControlsPlayWithKodi.setOnClickListener(this);
if (DEBUG) { if (DEBUG) {
binding.detailControlsCrashThePlayer.setOnClickListener( binding.detailControlsCrashThePlayer.setOnClickListener(
v -> VideoDetailPlayerCrasher.onCrashThePlayer(this.player, getLayoutInflater()) v -> VideoDetailPlayerCrasher.onCrashThePlayer(
this.getContext(),
this.player,
getLayoutInflater())
); );
} }

View File

@ -10,6 +10,7 @@ import android.widget.RadioGroup;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
@ -85,9 +86,12 @@ public final class VideoDetailPlayerCrasher {
: R.style.DarkTheme); : R.style.DarkTheme);
} }
public static void onCrashThePlayer(final Player player, final LayoutInflater layoutInflater) { public static void onCrashThePlayer(
final Context context = player.getContext(); @NonNull final Context context,
if (!isPlayerAvailable(player)) { @Nullable final Player player,
@NonNull final LayoutInflater layoutInflater
) {
if (player == null) {
Log.d(TAG, "Player is not available"); Log.d(TAG, "Player is not available");
Toast.makeText(context, "Player is not available", Toast.LENGTH_SHORT) Toast.makeText(context, "Player is not available", Toast.LENGTH_SHORT)
.show(); .show();
@ -152,8 +156,4 @@ public final class VideoDetailPlayerCrasher {
exPlayer); exPlayer);
} }
} }
private static boolean isPlayerAvailable(final Player player) {
return player != null;
}
} }