mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2025-07-12 06:53:13 +00:00
VideoPlaybackResolver: implicit -1 videoIndex
All functions that set videoIndex return `-1` if the list is empty, so we don’t have to check manually for that case. I’m somewhat more questioning why `StreamInfoTag.of` allows the index to be out-of-bounds in the constructor, that should be an error.
This commit is contained in:
parent
71d88d0bc0
commit
64c68cf2f1
@ -85,9 +85,7 @@ public class VideoPlaybackResolver implements PlaybackResolver {
|
|||||||
getFilteredAudioStreams(context, info.getAudioStreams());
|
getFilteredAudioStreams(context, info.getAudioStreams());
|
||||||
|
|
||||||
int videoIndex = -999;
|
int videoIndex = -999;
|
||||||
if (videoStreamsList.isEmpty()) {
|
if (playbackQuality == null) {
|
||||||
videoIndex = -1;
|
|
||||||
} else if (playbackQuality == null) {
|
|
||||||
switch (selectedPlayer) {
|
switch (selectedPlayer) {
|
||||||
case MAIN -> {
|
case MAIN -> {
|
||||||
videoIndex = ListHelper.getDefaultResolutionIndex(
|
videoIndex = ListHelper.getDefaultResolutionIndex(
|
||||||
|
@ -73,7 +73,7 @@ public final class ListHelper {
|
|||||||
/**
|
/**
|
||||||
* @param context Android app context
|
* @param context Android app context
|
||||||
* @param videoStreams list of the video streams to check
|
* @param videoStreams list of the video streams to check
|
||||||
* @return index of the video stream with the default index
|
* @return index of the video stream with the default index, -1 if `videoStreams` is empty
|
||||||
* @see #getDefaultResolutionIndex(String, String, MediaFormat, List)
|
* @see #getDefaultResolutionIndex(String, String, MediaFormat, List)
|
||||||
*/
|
*/
|
||||||
public static int getDefaultResolutionIndex(final Context context,
|
public static int getDefaultResolutionIndex(final Context context,
|
||||||
@ -87,7 +87,7 @@ public final class ListHelper {
|
|||||||
/**
|
/**
|
||||||
* @param context Android app context
|
* @param context Android app context
|
||||||
* @param videoStreams list of the video streams to check
|
* @param videoStreams list of the video streams to check
|
||||||
* @return index of the video stream with the default index
|
* @return index of the video stream with the default index, -1 if `videoStreams` is empty
|
||||||
* @see #getDefaultResolutionIndex(String, String, MediaFormat, List)
|
* @see #getDefaultResolutionIndex(String, String, MediaFormat, List)
|
||||||
*/
|
*/
|
||||||
public static int getPopupDefaultResolutionIndex(final Context context,
|
public static int getPopupDefaultResolutionIndex(final Context context,
|
||||||
@ -408,17 +408,19 @@ public final class ListHelper {
|
|||||||
* on the parameters defaultResolution and defaultFormat.
|
* on the parameters defaultResolution and defaultFormat.
|
||||||
*
|
*
|
||||||
* @param defaultResolution the default resolution to look for
|
* @param defaultResolution the default resolution to look for
|
||||||
|
* (a resolution string or `bestResolutionKey`).
|
||||||
* @param bestResolutionKey key of the best resolution
|
* @param bestResolutionKey key of the best resolution
|
||||||
* @param defaultFormat the default format to look for
|
* @param defaultFormat the default format to look for
|
||||||
* @param videoStreams a mutable list of the video streams to check (it will be sorted in
|
* @param videoStreams a mutable list of the video streams to check (it will be sorted in
|
||||||
* place)
|
* place)
|
||||||
* @return index of the default resolution&format in the sorted videoStreams
|
* @return index of the default resolution&format in the sorted videoStreams,
|
||||||
|
* -1 if `videoStreams` is empty
|
||||||
*/
|
*/
|
||||||
static int getDefaultResolutionIndex(final String defaultResolution,
|
static int getDefaultResolutionIndex(final String defaultResolution,
|
||||||
final String bestResolutionKey,
|
final String bestResolutionKey,
|
||||||
final MediaFormat defaultFormat,
|
final MediaFormat defaultFormat,
|
||||||
@Nullable final List<VideoStream> videoStreams) {
|
@NonNull final List<VideoStream> videoStreams) {
|
||||||
if (videoStreams == null || videoStreams.isEmpty()) {
|
if (videoStreams.isEmpty()) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -626,11 +628,13 @@ public final class ListHelper {
|
|||||||
* @param context Android app context
|
* @param context Android app context
|
||||||
* @param defaultResolution the default resolution
|
* @param defaultResolution the default resolution
|
||||||
* @param videoStreams the list of video streams to check
|
* @param videoStreams the list of video streams to check
|
||||||
* @return the index of the preferred video stream
|
* @return the index of the preferred video stream, -1 if `videoStreams` is empty
|
||||||
*/
|
*/
|
||||||
public static int getDefaultResolutionWithDefaultFormat(@NonNull final Context context,
|
public static int getDefaultResolutionWithDefaultFormat(
|
||||||
final String defaultResolution,
|
@NonNull final Context context,
|
||||||
final List<VideoStream> videoStreams) {
|
final String defaultResolution,
|
||||||
|
@NonNull final List<VideoStream> videoStreams
|
||||||
|
) {
|
||||||
final MediaFormat defaultFormat = getDefaultFormat(context,
|
final MediaFormat defaultFormat = getDefaultFormat(context,
|
||||||
R.string.default_video_format_key, R.string.default_video_format_value);
|
R.string.default_video_format_key, R.string.default_video_format_value);
|
||||||
return getDefaultResolutionIndex(defaultResolution,
|
return getDefaultResolutionIndex(defaultResolution,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user