Skip to content

Commit

Permalink
Updated the track selection to include the group index (#634)
Browse files Browse the repository at this point in the history
  • Loading branch information
brianwernick authored Jul 25, 2018
1 parent 18404e5 commit 871d0d7
Show file tree
Hide file tree
Showing 13 changed files with 99 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.novoda:bintray-release:0.8.1'
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,25 @@ public boolean trackSelectionAvailable() {
*
* @param trackType The type for the track to switch to the selected index
* @param trackIndex The index for the track to switch to
* @deprecated Use {@link #setTrack(ExoMedia.RendererType, int, int)}
*/
@Deprecated
public void setTrack(ExoMedia.RendererType trackType, int trackIndex) {
audioPlayerImpl.setTrack(trackType, trackIndex);
}

/**
* Changes to the track with <code>trackIndex</code> for the specified
* <code>trackType</code>
*
* @param trackType The type for the track to switch to the selected index
* @param groupIndex The index for the group in the {@link TrackGroupArray} specified by the <code>trackType</code>
* @param trackIndex The index for the track to switch to
*/
public void setTrack(ExoMedia.RendererType trackType, int groupIndex, int trackIndex) {
audioPlayerImpl.setTrack(trackType, groupIndex, trackIndex);
}

/**
* Retrieves a list of available tracks to select from. Typically {@link #trackSelectionAvailable()}
* should be called before this.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,14 @@ public interface AudioPlayerApi {

boolean trackSelectionAvailable();

/**
* @deprecated use {@link #setTrack(ExoMedia.RendererType, int, int)}
*/
@Deprecated
void setTrack(@NonNull ExoMedia.RendererType type, int trackIndex);

void setTrack(@NonNull ExoMedia.RendererType type, int groupIndex, int trackIndex);

/**
* Retrieves a list of available tracks to select from. Typically {@link #trackSelectionAvailable()}
* should be called before this.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,14 @@ interface OnSurfaceSizeChanged {

boolean trackSelectionAvailable();

/**
* @deprecated use {@link #setTrack(ExoMedia.RendererType, int, int)}
*/
@Deprecated
void setTrack(@NonNull ExoMedia.RendererType type, int trackIndex);

void setTrack(@NonNull ExoMedia.RendererType type, int groupIndex, int trackIndex);

/**
* Retrieves a list of available tracks to select from. Typically {@link #trackSelectionAvailable()}
* should be called before this.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ public void setTrack(@NonNull ExoMedia.RendererType type, int trackIndex) {
exoMediaPlayer.setSelectedTrack(type, trackIndex);
}

@Override
public void setTrack(@NonNull ExoMedia.RendererType type, int groupIndex, int trackIndex) {
exoMediaPlayer.setSelectedTrack(type, groupIndex, trackIndex);
}

@Nullable
@Override
public Map<ExoMedia.RendererType, TrackGroupArray> getAvailableTracks() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,12 @@ public boolean trackSelectionAvailable() {

@Override
public void setTrack(@NonNull ExoMedia.RendererType trackType, int trackIndex) {
//Purposefully left blank
// Purposefully left blank
}

@Override
public void setTrack(@NonNull ExoMedia.RendererType type, int groupIndex, int trackIndex) {
// Purposefully left blank
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import com.google.android.exoplayer2.metadata.Metadata;
import com.google.android.exoplayer2.metadata.MetadataOutput;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.TrackGroup;
import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.text.Cue;
import com.google.android.exoplayer2.text.TextOutput;
Expand Down Expand Up @@ -306,17 +307,31 @@ public int getSelectedTrackIndex(@NonNull RendererType type) {
return selectionOverride.tracks[0];
}

/**
* @deprecated Use {@link #setSelectedTrack(RendererType, int, int)}
*/
@Deprecated
public void setSelectedTrack(@NonNull RendererType type, int index) {
setSelectedTrack(type, 0, index);
}

public void setSelectedTrack(@NonNull RendererType type, int groupIndex, int trackIndex) {
// Retrieves the available tracks
int exoPlayerTrackIndex = getExoPlayerTrackIndex(type);
MappingTrackSelector.MappedTrackInfo mappedTrackInfo = trackSelector.getCurrentMappedTrackInfo();
TrackGroupArray trackGroupArray = mappedTrackInfo == null ? null : mappedTrackInfo.getTrackGroups(exoPlayerTrackIndex);
if (trackGroupArray == null || trackGroupArray.length == 0) {
if (trackGroupArray == null || trackGroupArray.length == 0 || trackGroupArray.length <= groupIndex) {
return;
}

// Finds the requested group
TrackGroup group = trackGroupArray.get(groupIndex);
if (group == null || group.length <= trackIndex) {
return;
}

// Specifies the correct track to use
DefaultTrackSelector.SelectionOverride selectionOverride = new DefaultTrackSelector.SelectionOverride(exoPlayerTrackIndex, index);
DefaultTrackSelector.SelectionOverride selectionOverride = new DefaultTrackSelector.SelectionOverride(groupIndex, trackIndex);
trackSelector.setParameters(trackSelector.buildUponParameters().setSelectionOverride(exoPlayerTrackIndex, trackGroupArray, selectionOverride));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ public void setTrack(@NonNull ExoMedia.RendererType trackType, int trackIndex) {
delegate.setTrack(trackType, trackIndex);
}

@Override
public void setTrack(@NonNull ExoMedia.RendererType type, int groupIndex, int trackIndex) {
delegate.setTrack(type, groupIndex, trackIndex);
}

@Nullable
@Override
public Map<ExoMedia.RendererType, TrackGroupArray> getAvailableTracks() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ public void setTrack(@NonNull ExoMedia.RendererType trackType, int trackIndex) {
delegate.setTrack(trackType, trackIndex);
}

@Override
public void setTrack(@NonNull ExoMedia.RendererType type, int groupIndex, int trackIndex) {
delegate.setTrack(type, groupIndex, trackIndex);
}

@Nullable
@Override
public Map<ExoMedia.RendererType, TrackGroupArray> getAvailableTracks() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,18 @@ public boolean trackSelectionAvailable() {
return true;
}

/**
* @deprecated use {@link #setTrack(ExoMedia.RendererType, int, int)}
*/
@Deprecated
public void setTrack(ExoMedia.RendererType trackType, int trackIndex) {
exoMediaPlayer.setSelectedTrack(trackType, trackIndex);
}

public void setTrack(@NonNull ExoMedia.RendererType trackType, int groupIndex, int trackIndex) {
exoMediaPlayer.setSelectedTrack(trackType, groupIndex, trackIndex);
}

@Nullable
public Map<ExoMedia.RendererType, TrackGroupArray> getAvailableTracks() {
return exoMediaPlayer.getAvailableTracks();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,12 @@ public boolean trackSelectionAvailable() {

@Override
public void setTrack(@NonNull ExoMedia.RendererType trackType, int trackIndex) {
//Purposefully left blank
// Purposefully left blank
}

@Override
public void setTrack(@NonNull ExoMedia.RendererType type, int groupIndex, int trackIndex) {
// Purposefully left blank
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,12 @@ public boolean trackSelectionAvailable() {

@Override
public void setTrack(@NonNull ExoMedia.RendererType trackType, int trackIndex) {
//Purposefully left blank
// Purposefully left blank
}

@Override
public void setTrack(@NonNull ExoMedia.RendererType type, int groupIndex, int trackIndex) {
// Purposefully left blank
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -661,11 +661,25 @@ public boolean trackSelectionAvailable() {
*
* @param trackType The type for the track to switch to the selected index
* @param trackIndex The index for the track to switch to
* @deprecated Use {@link #setTrack(ExoMedia.RendererType, int, int)}
*/
@Deprecated
public void setTrack(ExoMedia.RendererType trackType, int trackIndex) {
videoViewImpl.setTrack(trackType, trackIndex);
}

/**
* Changes to the track with <code>trackIndex</code> for the specified
* <code>trackType</code>
*
* @param trackType The type for the track to switch to the selected index
* @param groupIndex The index for the group in the {@link TrackGroupArray} specified by the <code>trackType</code>
* @param trackIndex The index for the track to switch to
*/
public void setTrack(ExoMedia.RendererType trackType, int groupIndex, int trackIndex) {
videoViewImpl.setTrack(trackType, groupIndex, trackIndex);
}

/**
* Retrieves a list of available tracks to select from. Typically {@link #trackSelectionAvailable()}
* should be called before this.
Expand Down

0 comments on commit 871d0d7

Please sign in to comment.