ListHelper { static int getMostCompactAudioIndex(@Nullable MediaFormat format, final List<AudioStream> audioStreams) { int result = -1; if (audioStreams != null) { while (result == -1) { AudioStream prevStream = null; for (int idx = 0; idx < audioStreams.size(); idx++) { final AudioStream stream = audioStreams.get(idx); if ((format == null || stream.getFormat() == format) && (prevStream == null || compareAudioStreamBitrate(prevStream, stream, AUDIO_FORMAT_EFFICIENCY_RANKING) > 0)) { prevStream = stream; result = idx; } } if (result == -1 && format == null) { break; } format = null; } } return result; } private  ListHelper(); static int getDefaultResolutionIndex(final Context context,
                                                final List<VideoStream> videoStreams); static int getResolutionIndex(final Context context,
                                         final List<VideoStream> videoStreams,
                                         final String defaultResolution); static int getPopupDefaultResolutionIndex(final Context context,
                                                     final List<VideoStream> videoStreams); static int getPopupResolutionIndex(final Context context,
                                              final List<VideoStream> videoStreams,
                                              final String defaultResolution); static int getDefaultAudioFormat(final Context context,
                                            final List<AudioStream> audioStreams); static List<VideoStream> getSortedStreamVideosList(final Context context,
                                                              final List<VideoStream> videoStreams,
                                                              final List<VideoStream>
                                                                      videoOnlyStreams,
                                                              final boolean ascendingOrder); static boolean isMeteredNetwork(final Context context);  }
@Test public void getLowestQualityAudioFormatTest() { AudioStream stream = AUDIO_STREAMS_TEST_LIST.get(ListHelper.getMostCompactAudioIndex( MediaFormat.M4A, AUDIO_STREAMS_TEST_LIST)); assertEquals(128, stream.average_bitrate); assertEquals(MediaFormat.M4A, stream.getFormat()); stream = AUDIO_STREAMS_TEST_LIST.get(ListHelper.getMostCompactAudioIndex( MediaFormat.WEBMA, AUDIO_STREAMS_TEST_LIST)); assertEquals(64, stream.average_bitrate); assertEquals(MediaFormat.WEBMA, stream.getFormat()); stream = AUDIO_STREAMS_TEST_LIST.get(ListHelper.getMostCompactAudioIndex( MediaFormat.MP3, AUDIO_STREAMS_TEST_LIST)); assertEquals(64, stream.average_bitrate); assertEquals(MediaFormat.MP3, stream.getFormat()); }
@Test public void getLowestQualityAudioFormatPreferredAbsent() { List<AudioStream> testList = new ArrayList<>(Arrays.asList( new AudioStream("", MediaFormat.M4A, 128), new AudioStream("", MediaFormat.WEBMA, 192))); AudioStream stream = testList.get(ListHelper.getMostCompactAudioIndex( MediaFormat.MP3, testList)); assertEquals(128, stream.average_bitrate); assertEquals(MediaFormat.M4A, stream.getFormat()); testList.add(new AudioStream("", MediaFormat.WEBMA, 128)); stream = testList.get(ListHelper.getMostCompactAudioIndex(MediaFormat.MP3, testList)); assertEquals(128, stream.average_bitrate); assertEquals(MediaFormat.WEBMA, stream.getFormat()); testList = new ArrayList<>(Arrays.asList( new AudioStream("", MediaFormat.WEBMA, 192), new AudioStream("", MediaFormat.M4A, 192), new AudioStream("", MediaFormat.WEBMA, 256), new AudioStream("", MediaFormat.M4A, 192), new AudioStream("", MediaFormat.WEBMA, 192), new AudioStream("", MediaFormat.M4A, 192))); stream = testList.get(ListHelper.getMostCompactAudioIndex(MediaFormat.MP3, testList)); assertEquals(192, stream.average_bitrate); assertEquals(MediaFormat.WEBMA, stream.getFormat()); stream = testList.get(ListHelper.getMostCompactAudioIndex(null, testList)); assertEquals(192, stream.average_bitrate); assertEquals(MediaFormat.WEBMA, stream.getFormat()); }
@Test public void getLowestQualityAudioNull() { assertEquals(-1, ListHelper.getMostCompactAudioIndex(null, null)); assertEquals(-1, ListHelper.getMostCompactAudioIndex(null, new ArrayList<>())); }