From 8978187c6429407abf6f5b23ed1bc3f67bcaf30d Mon Sep 17 00:00:00 2001 From: Stypox Date: Tue, 16 Feb 2021 16:54:44 +0100 Subject: [PATCH] Improve code style and fix some warnings Removed a textTrack null check on a now- NonNull method Added a error type switch case (TIMEOUT) --- app/src/main/java/org/schabi/newpipe/player/Player.java | 9 ++++++--- .../org/schabi/newpipe/player/helper/LoadController.java | 7 ++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/Player.java b/app/src/main/java/org/schabi/newpipe/player/Player.java index 535a5033ad8..0a10a2cb731 100644 --- a/app/src/main/java/org/schabi/newpipe/player/Player.java +++ b/app/src/main/java/org/schabi/newpipe/player/Player.java @@ -1433,7 +1433,7 @@ public float getPlaybackPitch() { } public boolean getPlaybackSkipSilence() { - return simpleExoPlayer != null + return !exoPlayerIsNull() && simpleExoPlayer.getAudioComponent() != null && simpleExoPlayer.getAudioComponent().getSkipSilenceEnabled(); } @@ -1460,7 +1460,9 @@ public void setPlaybackParameters(final float speed, final float pitch, savePlaybackParametersToPrefs(this, roundedSpeed, roundedPitch, skipSilence); simpleExoPlayer.setPlaybackParameters( new PlaybackParameters(roundedSpeed, roundedPitch)); - simpleExoPlayer.getAudioComponent().setSkipSilenceEnabled(skipSilence); + if (simpleExoPlayer.getAudioComponent() != null) { + simpleExoPlayer.getAudioComponent().setSkipSilenceEnabled(skipSilence); + } } //endregion @@ -2336,6 +2338,7 @@ public void onPlayerError(@NonNull final ExoPlaybackException error) { case ExoPlaybackException.TYPE_OUT_OF_MEMORY: case ExoPlaybackException.TYPE_REMOTE: case ExoPlaybackException.TYPE_RENDERER: + case ExoPlaybackException.TYPE_TIMEOUT: default: showUnrecoverableError(error); onPlaybackShutdown(); @@ -3358,7 +3361,7 @@ private void onTextTracksChanged() { final List availableLanguages = new ArrayList<>(textTracks.length); for (int i = 0; i < textTracks.length; i++) { final TrackGroup textTrack = textTracks.get(i); - if (textTrack.length > 0 && textTrack.getFormat(0) != null) { + if (textTrack.length > 0) { availableLanguages.add(textTrack.getFormat(0).language); } } diff --git a/app/src/main/java/org/schabi/newpipe/player/helper/LoadController.java b/app/src/main/java/org/schabi/newpipe/player/helper/LoadController.java index 162872267a6..ba9a2f1ec4c 100644 --- a/app/src/main/java/org/schabi/newpipe/player/helper/LoadController.java +++ b/app/src/main/java/org/schabi/newpipe/player/helper/LoadController.java @@ -81,12 +81,13 @@ public boolean retainBackBufferFromKeyframe() { @Override public boolean shouldContinueLoading(final long playbackPositionUs, - final long bufferedDurationUs, final float playbackSpeed) { + final long bufferedDurationUs, + final float playbackSpeed) { if (!preloadingEnabled) { return false; } - return internalLoadControl.shouldContinueLoading(playbackPositionUs, bufferedDurationUs, - playbackSpeed); + return internalLoadControl.shouldContinueLoading( + playbackPositionUs, bufferedDurationUs, playbackSpeed); } @Override