@@ -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 ();
0 commit comments