use of com.google.android.exoplayer2.trackselection.TrackSelectionOverrides in project ExoPlayer by google.
the class TrackSelectionOverridesTest method addOverride_onDifferentGroups_addsOverride.
@Test
public void addOverride_onDifferentGroups_addsOverride() {
TrackSelectionOverride override1 = new TrackSelectionOverride(newTrackGroupWithIds(1));
TrackSelectionOverride override2 = new TrackSelectionOverride(newTrackGroupWithIds(2));
TrackSelectionOverrides trackSelectionOverrides = new TrackSelectionOverrides.Builder().addOverride(override1).addOverride(override2).build();
assertThat(trackSelectionOverrides.asList()).containsExactly(override1, override2);
assertThat(trackSelectionOverrides.getOverride(override1.trackGroup)).isEqualTo(override1);
assertThat(trackSelectionOverrides.getOverride(override2.trackGroup)).isEqualTo(override2);
}
use of com.google.android.exoplayer2.trackselection.TrackSelectionOverrides in project ExoPlayer by google.
the class TrackSelectionOverridesTest method clearOverride_ofTypeGroup_removesOverride.
@Test
public void clearOverride_ofTypeGroup_removesOverride() {
TrackSelectionOverride override1 = new TrackSelectionOverride(AAC_TRACK_GROUP);
TrackSelectionOverride override2 = new TrackSelectionOverride(newTrackGroupWithIds(1));
TrackSelectionOverrides trackSelectionOverrides = new TrackSelectionOverrides.Builder().addOverride(override1).addOverride(override2).clearOverride(override2.trackGroup).build();
assertThat(trackSelectionOverrides.asList()).containsExactly(override1);
assertThat(trackSelectionOverrides.getOverride(override1.trackGroup)).isEqualTo(override1);
}
use of com.google.android.exoplayer2.trackselection.TrackSelectionOverrides in project ExoPlayer by google.
the class TrackSelectionOverridesTest method roundTripViaBundle_withOverrides_yieldsEqualInstance.
@Test
public void roundTripViaBundle_withOverrides_yieldsEqualInstance() {
TrackSelectionOverrides trackSelectionOverrides = new TrackSelectionOverrides.Builder().setOverrideForType(new TrackSelectionOverride(newTrackGroupWithIds(3, 4), ImmutableList.of(1))).addOverride(new TrackSelectionOverride(newTrackGroupWithIds(5, 6))).build();
TrackSelectionOverrides fromBundle = TrackSelectionOverrides.CREATOR.fromBundle(trackSelectionOverrides.toBundle());
assertThat(fromBundle).isEqualTo(trackSelectionOverrides);
assertThat(fromBundle.asList()).isEqualTo(trackSelectionOverrides.asList());
}
use of com.google.android.exoplayer2.trackselection.TrackSelectionOverrides in project ExoPlayer by google.
the class TrackSelectionOverridesTest method clearOverridesOfType_ofTypeAudio_removesAudioOverride.
@Test
public void clearOverridesOfType_ofTypeAudio_removesAudioOverride() {
TrackSelectionOverride override1 = new TrackSelectionOverride(AAC_TRACK_GROUP);
TrackSelectionOverride override2 = new TrackSelectionOverride(newTrackGroupWithIds(1));
TrackSelectionOverrides trackSelectionOverrides = new TrackSelectionOverrides.Builder().addOverride(override1).addOverride(override2).clearOverridesOfType(C.TRACK_TYPE_AUDIO).build();
assertThat(trackSelectionOverrides.asList()).containsExactly(override2);
assertThat(trackSelectionOverrides.getOverride(override2.trackGroup)).isEqualTo(override2);
}
use of com.google.android.exoplayer2.trackselection.TrackSelectionOverrides in project odysee-android by OdyseeTeam.
the class FileViewFragment method setPlayerQuality.
private void setPlayerQuality(Player player, int quality) {
TracksInfo tracksInfo = player.getCurrentTracksInfo();
int selectedQuality = 0;
for (TrackGroupInfo groupInfo : tracksInfo.getTrackGroupInfos()) {
if (groupInfo.getTrackType() != C.TRACK_TYPE_VIDEO)
continue;
TrackGroup group = groupInfo.getTrackGroup();
TrackSelectionOverrides overrides;
if (quality == AUTO_QUALITY_ID || !MainActivity.videoIsTranscoded) {
overrides = new TrackSelectionOverrides.Builder().clearOverridesOfType(C.TRACK_TYPE_VIDEO).build();
// Force it to AUTO_QUALITY_ID to override the default quality setting on non-transcoded videos
selectedQuality = AUTO_QUALITY_ID;
} else {
ArrayList<Integer> availableQualities = new ArrayList<>();
for (int i = 0; i < group.length; i++) {
availableQualities.add(group.getFormat(i).height);
}
int selectedQualityIndex;
// Check if the chosen quality is lower than the lowest available quality
int lowestQuality = Collections.min(availableQualities);
if (quality <= lowestQuality) {
// <= short path for when the quality matches the lowest
selectedQuality = lowestQuality;
selectedQualityIndex = availableQualities.indexOf(lowestQuality);
} else {
// Otherwise find the highest available quality that is less than the chosen quality
for (int i = 0; i < availableQualities.size(); i++) {
int q = availableQualities.get(i);
if (q <= quality && groupInfo.isTrackSupported(i) && q > selectedQuality) {
selectedQuality = q;
}
}
selectedQualityIndex = availableQualities.indexOf(selectedQuality);
}
if (selectedQualityIndex != -1) {
TrackSelectionOverride override = new TrackSelectionOverride(group, Collections.singletonList(selectedQualityIndex));
overrides = new TrackSelectionOverrides.Builder().addOverride(override).build();
} else {
// If quality can't be found use Auto quality
overrides = new TrackSelectionOverrides.Builder().clearOverridesOfType(C.TRACK_TYPE_VIDEO).build();
}
}
player.setTrackSelectionParameters(player.getTrackSelectionParameters().buildUpon().setTrackSelectionOverrides(overrides).build());
MainActivity.videoQuality = selectedQuality;
updateQualityView(getView());
break;
}
}
Aggregations