Skip to content

Commit b567d42

Browse files
committed
fix: small codestyle fixes
1 parent 2edc223 commit b567d42

7 files changed

Lines changed: 80 additions & 52 deletions

File tree

app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public class DownloadDialog extends DialogFragment
103103
@State
104104
AudioTracksWrapper wrappedAudioTracks;
105105
@State
106-
int selectedAudioStreamIndex;
106+
int selectedAudioTrackIndex;
107107
@State
108108
int selectedVideoIndex; // set in the constructor
109109
@State
@@ -173,7 +173,7 @@ public DownloadDialog(@NonNull final Context context, @NonNull final StreamInfo
173173
final List<List<AudioStream>> groupedAudioStreams =
174174
ListHelper.getGroupedAudioStreams(context, audioStreams);
175175
this.wrappedAudioTracks = new AudioTracksWrapper(groupedAudioStreams, context);
176-
this.selectedAudioStreamIndex =
176+
this.selectedAudioTrackIndex =
177177
ListHelper.getDefaultAudioTrackGroup(context, groupedAudioStreams);
178178

179179
// TODO: Adapt this code when the downloader support other types of stream deliveries
@@ -433,7 +433,7 @@ private void setupAudioTrackSpinner() {
433433
}
434434

435435
dialogBinding.audioTrackSpinner.setAdapter(audioTrackAdapter);
436-
dialogBinding.audioTrackSpinner.setSelection(selectedAudioStreamIndex);
436+
dialogBinding.audioTrackSpinner.setSelection(selectedAudioTrackIndex);
437437
}
438438

439439
private void setupAudioSpinner() {
@@ -619,8 +619,8 @@ public void onItemSelected(final AdapterView<?> parent,
619619
onItemSelectedSetFileName();
620620
break;
621621
case R.id.audio_track_spinner:
622-
final boolean trackChanged = selectedAudioStreamIndex != position;
623-
selectedAudioStreamIndex = position;
622+
final boolean trackChanged = selectedAudioTrackIndex != position;
623+
selectedAudioTrackIndex = position;
624624
if (trackChanged) {
625625
updateSecondaryStreams();
626626
fetchStreamsSize();
@@ -726,10 +726,10 @@ private void setRadioButtonsState(final boolean enabled) {
726726
}
727727

728728
private StreamSizeWrapper<AudioStream> getWrappedAudioStreams() {
729-
if (selectedAudioStreamIndex < 0 || selectedAudioStreamIndex > wrappedAudioTracks.size()) {
729+
if (selectedAudioTrackIndex < 0 || selectedAudioTrackIndex > wrappedAudioTracks.size()) {
730730
return StreamSizeWrapper.empty();
731731
}
732-
return wrappedAudioTracks.getTracksList().get(selectedAudioStreamIndex);
732+
return wrappedAudioTracks.getTracksList().get(selectedAudioTrackIndex);
733733
}
734734

735735
private int getSubtitleIndexBy(@NonNull final List<SubtitlesStream> streams) {

app/src/main/java/org/schabi/newpipe/player/PlayQueueActivity.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -667,11 +667,8 @@ private void onAudioTrackClick(final int itemId) {
667667
return;
668668
}
669669

670-
player.saveStreamProgressState();
671670
final String newAudioTrack = availableStreams.get(itemId).getAudioTrackId();
672-
player.setRecovery();
673671
player.setAudioTrack(newAudioTrack);
674-
player.reloadPlayQueueManager();
675672
});
676673
}
677674
}

app/src/main/java/org/schabi/newpipe/player/Player.java

Lines changed: 54 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,18 @@ public final class Player implements PlaybackListener, Listener {
180180
//////////////////////////////////////////////////////////////////////////*/
181181

182182
// play queue might be null e.g. while player is starting
183-
@Nullable private PlayQueue playQueue;
183+
@Nullable
184+
private PlayQueue playQueue;
184185

185-
@Nullable private MediaSourceManager playQueueManager;
186+
@Nullable
187+
private MediaSourceManager playQueueManager;
186188

187-
@Nullable private PlayQueueItem currentItem;
188-
@Nullable private MediaItemTag currentMetadata;
189-
@Nullable private Bitmap currentThumbnail;
189+
@Nullable
190+
private PlayQueueItem currentItem;
191+
@Nullable
192+
private MediaItemTag currentMetadata;
193+
@Nullable
194+
private Bitmap currentThumbnail;
190195

191196
/*//////////////////////////////////////////////////////////////////////////
192197
// Player
@@ -195,12 +200,17 @@ public final class Player implements PlaybackListener, Listener {
195200
private ExoPlayer simpleExoPlayer;
196201
private AudioReactor audioReactor;
197202

198-
@NonNull private final DefaultTrackSelector trackSelector;
199-
@NonNull private final LoadController loadController;
200-
@NonNull private final DefaultRenderersFactory renderFactory;
203+
@NonNull
204+
private final DefaultTrackSelector trackSelector;
205+
@NonNull
206+
private final LoadController loadController;
207+
@NonNull
208+
private final DefaultRenderersFactory renderFactory;
201209

202-
@NonNull private final VideoPlaybackResolver videoResolver;
203-
@NonNull private final AudioPlaybackResolver audioResolver;
210+
@NonNull
211+
private final VideoPlaybackResolver videoResolver;
212+
@NonNull
213+
private final AudioPlaybackResolver audioResolver;
204214

205215
private final PlayerService service; //TODO try to remove and replace everything with context
206216

@@ -225,24 +235,32 @@ public final class Player implements PlaybackListener, Listener {
225235

226236
private BroadcastReceiver broadcastReceiver;
227237
private IntentFilter intentFilter;
228-
@Nullable private PlayerServiceEventListener fragmentListener = null;
229-
@Nullable private PlayerEventListener activityListener = null;
238+
@Nullable
239+
private PlayerServiceEventListener fragmentListener = null;
240+
@Nullable
241+
private PlayerEventListener activityListener = null;
230242

231-
@NonNull private final SerialDisposable progressUpdateDisposable = new SerialDisposable();
232-
@NonNull private final CompositeDisposable databaseUpdateDisposable = new CompositeDisposable();
243+
@NonNull
244+
private final SerialDisposable progressUpdateDisposable = new SerialDisposable();
245+
@NonNull
246+
private final CompositeDisposable databaseUpdateDisposable = new CompositeDisposable();
233247

234248
// This is the only listener we need for thumbnail loading, since there is always at most only
235249
// one thumbnail being loaded at a time. This field is also here to maintain a strong reference,
236250
// which would otherwise be garbage collected since Picasso holds weak references to targets.
237-
@NonNull private final Target currentThumbnailTarget;
251+
@NonNull
252+
private final Target currentThumbnailTarget;
238253

239254
/*//////////////////////////////////////////////////////////////////////////
240255
// Utils
241256
//////////////////////////////////////////////////////////////////////////*/
242257

243-
@NonNull private final Context context;
244-
@NonNull private final SharedPreferences prefs;
245-
@NonNull private final HistoryRecordManager recordManager;
258+
@NonNull
259+
private final Context context;
260+
@NonNull
261+
private final SharedPreferences prefs;
262+
@NonNull
263+
private final HistoryRecordManager recordManager;
246264

247265

248266
/*//////////////////////////////////////////////////////////////////////////
@@ -334,15 +352,15 @@ public void handleIntent(@NonNull final Intent intent) {
334352
isAudioOnly = audioPlayerSelected();
335353

336354
if (intent.hasExtra(PLAYBACK_QUALITY)) {
337-
setPlaybackQuality(intent.getStringExtra(PLAYBACK_QUALITY));
355+
videoResolver.setPlaybackQuality(intent.getStringExtra(PLAYBACK_QUALITY));
338356
}
339357

340358
// Resolve enqueue intents
341359
if (intent.getBooleanExtra(ENQUEUE, false) && playQueue != null) {
342360
playQueue.append(newQueue.getStreams());
343361
return;
344362

345-
// Resolve enqueue next intents
363+
// Resolve enqueue next intents
346364
} else if (intent.getBooleanExtra(ENQUEUE_NEXT, false) && playQueue != null) {
347365
final int currentIndex = playQueue.getIndex();
348366
playQueue.append(newQueue.getStreams());
@@ -914,7 +932,7 @@ public void triggerProgressUpdate() {
914932

915933
private Disposable getProgressUpdateDisposable() {
916934
return Observable.interval(PROGRESS_LOOP_INTERVAL_MILLIS, MILLISECONDS,
917-
AndroidSchedulers.mainThread())
935+
AndroidSchedulers.mainThread())
918936
.observeOn(AndroidSchedulers.mainThread())
919937
.subscribe(ignored -> triggerProgressUpdate(),
920938
error -> Log.e(TAG, "Progress update failure: ", error));
@@ -923,7 +941,6 @@ private Disposable getProgressUpdateDisposable() {
923941
//endregion
924942

925943

926-
927944
/*//////////////////////////////////////////////////////////////////////////
928945
// Playback states
929946
//////////////////////////////////////////////////////////////////////////*/
@@ -1247,7 +1264,7 @@ public void onEvents(@NonNull final com.google.android.exoplayer2.Player player,
12471264
.flatMap(MediaItemTag::getMaybeStreamInfo).orElse(null);
12481265
final MediaItemTag.AudioTrack previousAudioTrack =
12491266
Optional.ofNullable(currentMetadata)
1250-
.flatMap(MediaItemTag::getMaybeAudioTrack).orElse(null);
1267+
.flatMap(MediaItemTag::getMaybeAudioTrack).orElse(null);
12511268
currentMetadata = tag;
12521269

12531270
if (!currentMetadata.getErrors().isEmpty()) {
@@ -1270,9 +1287,9 @@ public void onEvents(@NonNull final com.google.android.exoplayer2.Player player,
12701287
updateMetadataWith(info);
12711288
} else if (previousAudioTrack == null
12721289
|| tag.getMaybeAudioTrack()
1273-
.map(t -> t.getSelectedAudioStreamIndex()
1274-
!= previousAudioTrack.getSelectedAudioStreamIndex())
1275-
.orElse(false)) {
1290+
.map(t -> t.getSelectedAudioStreamIndex()
1291+
!= previousAudioTrack.getSelectedAudioStreamIndex())
1292+
.orElse(false)) {
12761293
notifyAudioTrackUpdateToListeners();
12771294
}
12781295
});
@@ -1361,6 +1378,7 @@ public void onCues(@NonNull final CueGroup cueGroup) {
13611378
// Errors
13621379
//////////////////////////////////////////////////////////////////////////*/
13631380
//region Errors
1381+
13641382
/**
13651383
* Process exceptions produced by {@link com.google.android.exoplayer2.ExoPlayer ExoPlayer}.
13661384
* <p>There are multiple types of errors:</p>
@@ -1387,8 +1405,9 @@ public void onCues(@NonNull final CueGroup cueGroup) {
13871405
* For any error above that is <b>not</b> explicitly <b>catchable</b>, the player will
13881406
* create a notification so users are aware.
13891407
* </ul>
1408+
*
13901409
* @see com.google.android.exoplayer2.Player.Listener#onPlayerError(PlaybackException)
1391-
* */
1410+
*/
13921411
// Any error code not explicitly covered here are either unrelated to NewPipe use case
13931412
// (e.g. DRM) or not recoverable (e.g. Decoder error). In both cases, the player should
13941413
// shutdown.
@@ -2141,7 +2160,7 @@ private boolean playQueueManagerReloadingNeeded(final SourceType sourceType,
21412160
// because the stream source will be probably the same as the current played
21422161
if (sourceType == SourceType.VIDEO_WITH_SEPARATED_AUDIO
21432162
|| (sourceType == SourceType.VIDEO_WITH_AUDIO_OR_AUDIO_ONLY
2144-
&& isNullOrEmpty(streamInfo.getAudioStreams()))) {
2163+
&& isNullOrEmpty(streamInfo.getAudioStreams()))) {
21452164
// It's not needed to reload the play queue manager only if the content's stream type
21462165
// is a video stream, a live stream or an ended live stream
21472166
return !StreamTypeUtil.isVideo(streamType);
@@ -2203,12 +2222,18 @@ private boolean isLive() {
22032222
}
22042223

22052224
public void setPlaybackQuality(@Nullable final String quality) {
2225+
saveStreamProgressState();
2226+
setRecovery();
22062227
videoResolver.setPlaybackQuality(quality);
2228+
reloadPlayQueueManager();
22072229
}
22082230

22092231
public void setAudioTrack(@Nullable final String audioTrackId) {
2232+
saveStreamProgressState();
2233+
setRecovery();
22102234
videoResolver.setAudioTrack(audioTrackId);
22112235
audioResolver.setAudioTrack(audioTrackId);
2236+
reloadPlayQueueManager();
22122237
}
22132238

22142239

@@ -2286,7 +2311,7 @@ public PlayerUiList UIs() {
22862311

22872312
/**
22882313
* Get the video renderer index of the current playing stream.
2289-
*
2314+
* <p>
22902315
* This method returns the video renderer index of the current
22912316
* {@link MappingTrackSelector.MappedTrackInfo} or {@link #RENDERER_UNAVAILABLE} if the current
22922317
* {@link MappingTrackSelector.MappedTrackInfo} is null or if there is no video renderer index.

app/src/main/java/org/schabi/newpipe/player/resolver/AudioPlaybackResolver.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ public AudioPlaybackResolver(@NonNull final Context context,
3838
this.dataSource = dataSource;
3939
}
4040

41+
/**
42+
* Get a media source providing audio. If a service has no separate {@link AudioStream}s we
43+
* use a video stream as audio source to support audio background playback.
44+
*
45+
* @param info of the stream
46+
* @return the audio source to use or null if none could be found
47+
*/
4148
@Override
4249
@Nullable
4350
public MediaSource resolve(@NonNull final StreamInfo info) {

app/src/main/java/org/schabi/newpipe/player/ui/VideoPlayerUi.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ public abstract class VideoPlayerUi extends PlayerUi implements SeekBar.OnSeekBa
110110

111111
protected PlayerBinding binding;
112112
private final Handler controlsVisibilityHandler = new Handler(Looper.getMainLooper());
113-
@Nullable private SurfaceHolderCallback surfaceHolderCallback;
113+
@Nullable
114+
private SurfaceHolderCallback surfaceHolderCallback;
114115
boolean surfaceIsSetup = false;
115116

116117

@@ -533,6 +534,7 @@ public void onUpdateProgress(final int currentProgress,
533534

534535
/**
535536
* Sets the current duration into the corresponding elements.
537+
*
536538
* @param currentProgress the current progress, in milliseconds
537539
*/
538540
private void updatePlayBackElementsCurrentDuration(final int currentProgress) {
@@ -545,6 +547,7 @@ private void updatePlayBackElementsCurrentDuration(final int currentProgress) {
545547

546548
/**
547549
* Sets the video duration time into all control components (e.g. seekbar).
550+
*
548551
* @param duration the video duration, in milliseconds
549552
*/
550553
private void setVideoDurationToControls(final int duration) {
@@ -1261,11 +1264,8 @@ private void onQualityItemClick(@NonNull final MenuItem menuItem) {
12611264
return;
12621265
}
12631266

1264-
player.saveStreamProgressState();
12651267
final String newResolution = availableStreams.get(menuItemIndex).getResolution();
1266-
player.setRecovery();
12671268
player.setPlaybackQuality(newResolution);
1268-
player.reloadPlayQueueManager();
12691269

12701270
binding.qualityTextView.setText(menuItem.getTitle());
12711271
}
@@ -1285,11 +1285,8 @@ private void onAudioTrackItemClick(@NonNull final MenuItem menuItem) {
12851285
return;
12861286
}
12871287

1288-
player.saveStreamProgressState();
12891288
final String newAudioTrack = availableStreams.get(menuItemIndex).getAudioTrackId();
1290-
player.setRecovery();
12911289
player.setAudioTrack(newAudioTrack);
1292-
player.reloadPlayQueueManager();
12931290

12941291
binding.audioTrackTextView.setText(menuItem.getTitle());
12951292
}

app/src/main/java/org/schabi/newpipe/util/ListHelper.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -715,9 +715,9 @@ static Comparator<AudioStream> getAudioFormatComparator(
715715
/**
716716
* Get a {@link Comparator} to compare {@link AudioStream}s by their tracks.
717717
*
718-
* <p>In this order:</p>
718+
* <p>Tracks will be compared this order:</p>
719719
* <ol>
720-
* <li>If {@code preferOriginalAudio}: is original audio</li>
720+
* <li>If {@code preferOriginalAudio}: use original audio</li>
721721
* <li>Language matches {@code preferredLanguage}</li>
722722
* <li>
723723
* Track type ranks highest in this order:
@@ -752,9 +752,9 @@ private static Comparator<AudioStream> getAudioTrackComparator(
752752
/**
753753
* Get a {@link Comparator} to compare {@link AudioStream}s by their tracks.
754754
*
755-
* <p>In this order:</p>
755+
* <p>Tracks will be compared this order:</p>
756756
* <ol>
757-
* <li>If {@code preferOriginalAudio}: is original audio</li>
757+
* <li>If {@code preferOriginalAudio}: use original audio</li>
758758
* <li>Language matches {@code preferredLanguage}</li>
759759
* <li>
760760
* Track type ranks highest in this order:

app/src/main/java/org/schabi/newpipe/util/StreamItemAdapter.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ private boolean checkHasAnyVideoOnlyStreamWithNoSecondaryStream() {
224224
public static class StreamSizeWrapper<T extends Stream> implements Serializable {
225225
private static final StreamSizeWrapper<Stream> EMPTY =
226226
new StreamSizeWrapper<>(Collections.emptyList(), null);
227+
private static final int SIZE_UNSET = -2;
228+
227229
private final List<T> streamsList;
228230
private final long[] streamSizes;
229231
private final String unknownSize;
@@ -251,7 +253,7 @@ public static <X extends Stream> Single<Boolean> fetchSizeForWrapper(
251253
final Callable<Boolean> fetchAndSet = () -> {
252254
boolean hasChanged = false;
253255
for (final X stream : streamsWrapper.getStreamsList()) {
254-
if (streamsWrapper.getSizeInBytes(stream) > -2) {
256+
if (streamsWrapper.getSizeInBytes(stream) > SIZE_UNSET) {
255257
continue;
256258
}
257259

@@ -270,7 +272,7 @@ public static <X extends Stream> Single<Boolean> fetchSizeForWrapper(
270272
}
271273

272274
public void resetSizes() {
273-
Arrays.fill(streamSizes, -2);
275+
Arrays.fill(streamSizes, SIZE_UNSET);
274276
}
275277

276278
public static <X extends Stream> StreamSizeWrapper<X> empty() {

0 commit comments

Comments
 (0)