Search in sources :

Example 6 with TrackSelectionOverrides

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);
}
Also used : TrackSelectionOverride(com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride) Test(org.junit.Test)

Example 7 with TrackSelectionOverrides

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);
}
Also used : TrackSelectionOverride(com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride) Test(org.junit.Test)

Example 8 with TrackSelectionOverrides

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());
}
Also used : TrackSelectionOverride(com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride) Test(org.junit.Test)

Example 9 with TrackSelectionOverrides

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);
}
Also used : TrackSelectionOverride(com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride) Test(org.junit.Test)

Example 10 with TrackSelectionOverrides

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;
    }
}
Also used : TrackSelectionOverrides(com.google.android.exoplayer2.trackselection.TrackSelectionOverrides) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) TrackGroupInfo(com.google.android.exoplayer2.TracksInfo.TrackGroupInfo) ArrayList(java.util.ArrayList) TrackSelectionOverride(com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride) TracksInfo(com.google.android.exoplayer2.TracksInfo) SuppressLint(android.annotation.SuppressLint)

Aggregations

TrackSelectionOverride (com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride)8 Test (org.junit.Test)7 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)4 TrackSelectionOverrides (com.google.android.exoplayer2.trackselection.TrackSelectionOverrides)3 TracksInfo (com.google.android.exoplayer2.TracksInfo)2 SuppressLint (android.annotation.SuppressLint)1 PixelFormat (android.graphics.PixelFormat)1 Format (com.google.android.exoplayer2.Format)1 PlaybackException (com.google.android.exoplayer2.PlaybackException)1 TrackGroupInfo (com.google.android.exoplayer2.TracksInfo.TrackGroupInfo)1 TrackSelectionParameters (com.google.android.exoplayer2.trackselection.TrackSelectionParameters)1 ArrayList (java.util.ArrayList)1 MediaStream (org.jellyfin.apiclient.model.entities.MediaStream)1