Skip to content

Commit a1c5c94

Browse files
committed
Add some comments and a JavaDoc
1 parent 7a35641 commit a1c5c94

2 files changed

Lines changed: 28 additions & 6 deletions

File tree

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3295,9 +3295,18 @@ public MediaSource sourceOf(final PlayQueueItem item, final StreamInfo info) {
32953295
} else {
32963296
if (isAudioOnly
32973297
&& !videoResolver.wasLastResolvedVideoAndAudioSeparated().orElse(false)) {
3298+
// If the current info has only video streams with audio and if the stream is
3299+
// played as audio, we need to use the audio resolver, otherwise the video stream
3300+
// will be played in background.
32983301
return audioResolver.resolve(info);
32993302
}
33003303

3304+
// Even if the stream is played in background, we need to use the video resolver if the
3305+
// info played is separated video-only and audio-only streams; otherwise, if the audio
3306+
// resolver was called when the app was in background, the app will only stream audio
3307+
// when the user come back to the app and will never fetch the video stream.
3308+
// Note that the video is not fetched when the app is in background because the video
3309+
// renderer is fully disabled (see useVideoSource method).
33013310
return videoResolver.resolve(info);
33023311
}
33033312
}
@@ -4160,8 +4169,8 @@ private void useVideoSource(final boolean videoEnabled) {
41604169
}
41614170

41624171
isAudioOnly = !videoEnabled;
4163-
// When a user returns from background controls could be hidden
4164-
// but systemUI will be shown 100%. Hide it
4172+
// When a user returns from background, controls could be hidden but SystemUI will be shown
4173+
// 100%. Hide it.
41654174
if (!isAudioOnly && !isControlsVisible()) {
41664175
hideSystemUIIfNeeded();
41674176
}
@@ -4198,9 +4207,13 @@ Otherwise the video renderer will be just disabled (because there is no
41984207
final TrackGroupArray videoTrackGroupArray = Objects.requireNonNull(
41994208
trackSelector.getCurrentMappedTrackInfo()).getTrackGroups(videoRenderIndex);
42004209
if (videoEnabled) {
4210+
// Clearing the null selection override enable again the video stream (and its
4211+
// fetching).
42014212
trackSelector.setParameters(trackSelector.buildUponParameters()
42024213
.clearSelectionOverride(videoRenderIndex, videoTrackGroupArray));
42034214
} else {
4215+
// Using setRendererDisabled still fetch the video stream in background, contrary
4216+
// to setSelectionOverride with a null override.
42044217
trackSelector.setParameters(trackSelector.buildUponParameters()
42054218
.setSelectionOverride(videoRenderIndex, videoTrackGroupArray, null));
42064219
}
@@ -4436,6 +4449,15 @@ private void cleanupVideoSurface() {
44364449
}
44374450
//endregion
44384451

4452+
/**
4453+
* Get the video renderer index of the current playing stream.
4454+
*
4455+
* This method returns the video renderer index of the current
4456+
* {@link MappingTrackSelector.MappedTrackInfo} or {@link #RENDERER_UNAVAILABLE} if the current
4457+
* {@link MappingTrackSelector.MappedTrackInfo} is null or if there is no video renderer index.
4458+
*
4459+
* @return the video renderer index or {@link #RENDERER_UNAVAILABLE} if it cannot be get
4460+
*/
44394461
private int getVideoRendererIndex() {
44404462
final MappingTrackSelector.MappedTrackInfo mappedTrackInfo = trackSelector
44414463
.getCurrentMappedTrackInfo();

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,11 @@ public MediaSource resolve(@NonNull final StreamInfo info) {
128128
}
129129

130130
/**
131-
* Determines if the last resolved StreamInfo had separated audio and video streams
132-
* (or only audio).
131+
* Determine if the last resolved {@link StreamInfo} had separated audio and video streams (or
132+
* only audio).
133133
*
134-
* @return {@link Optional#empty()} if nothing was resolved
135-
* otherwise <code>true</code> or <code>false</code>
134+
* @return {@link Optional#empty()} if nothing was resolved, otherwise {@code true} or
135+
* {@code false}
136136
*/
137137
public Optional<Boolean> wasLastResolvedVideoAndAudioSeparated() {
138138
return Optional.ofNullable(wasLastResolvedVideoAndAudioSeparated);

0 commit comments

Comments
 (0)