diff --git a/demo/src/main/java/com/google/android/exoplayer2/demo/PlayerActivity.java b/demo/src/main/java/com/google/android/exoplayer2/demo/PlayerActivity.java
index 267c54cc054..243fcadce06 100644
--- a/demo/src/main/java/com/google/android/exoplayer2/demo/PlayerActivity.java
+++ b/demo/src/main/java/com/google/android/exoplayer2/demo/PlayerActivity.java
@@ -469,10 +469,12 @@ public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray tra
updateButtonVisibilities();
MappedTrackInfo mappedTrackInfo = trackSelector.getCurrentMappedTrackInfo();
if (mappedTrackInfo != null) {
- if (mappedTrackInfo.hasOnlyUnplayableTracks(C.TRACK_TYPE_VIDEO)) {
+ if (mappedTrackInfo.getTrackTypeRendererSupport(C.TRACK_TYPE_VIDEO)
+ == MappedTrackInfo.RENDERER_SUPPORT_UNSUPPORTED_TRACKS) {
showToast(R.string.error_unsupported_video);
}
- if (mappedTrackInfo.hasOnlyUnplayableTracks(C.TRACK_TYPE_AUDIO)) {
+ if (mappedTrackInfo.getTrackTypeRendererSupport(C.TRACK_TYPE_AUDIO)
+ == MappedTrackInfo.RENDERER_SUPPORT_UNSUPPORTED_TRACKS) {
showToast(R.string.error_unsupported_audio);
}
}
diff --git a/library/src/main/java/com/google/android/exoplayer2/trackselection/DefaultTrackSelector.java b/library/src/main/java/com/google/android/exoplayer2/trackselection/DefaultTrackSelector.java
index bf139c85a8f..79979401f7f 100644
--- a/library/src/main/java/com/google/android/exoplayer2/trackselection/DefaultTrackSelector.java
+++ b/library/src/main/java/com/google/android/exoplayer2/trackselection/DefaultTrackSelector.java
@@ -69,12 +69,12 @@ public static final class Parameters {
*
Non seamless adaptation is allowed.
* No max limit for video width/height.
* Video constraints are exceeded if no supported selection can be made otherwise.
- * Renderer capabilities are not exceeded even if no supported selection can be made.
+ * Renderer capabilities are exceeded if no supported selection can be made.
* No viewport width/height constraints are set.
*
*/
public Parameters() {
- this(null, null, false, true, Integer.MAX_VALUE, Integer.MAX_VALUE, true, false,
+ this(null, null, false, true, Integer.MAX_VALUE, Integer.MAX_VALUE, true, true,
Integer.MAX_VALUE, Integer.MAX_VALUE, true);
}
diff --git a/library/src/main/java/com/google/android/exoplayer2/trackselection/MappingTrackSelector.java b/library/src/main/java/com/google/android/exoplayer2/trackselection/MappingTrackSelector.java
index 7454ff6801c..77df9a2173a 100644
--- a/library/src/main/java/com/google/android/exoplayer2/trackselection/MappingTrackSelector.java
+++ b/library/src/main/java/com/google/android/exoplayer2/trackselection/MappingTrackSelector.java
@@ -18,6 +18,7 @@
import android.util.Pair;
import android.util.SparseArray;
import android.util.SparseBooleanArray;
+import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.RendererCapabilities;
import com.google.android.exoplayer2.source.TrackGroup;
@@ -138,8 +139,6 @@ public final boolean getRendererDisabled(int rendererIndex) {
* @param groups The {@link TrackGroupArray} for which the override should be applied.
* @param override The override.
*/
- // TODO - Don't allow overrides that select unsupported tracks, unless some flag has been
- // explicitly set by the user to indicate that they want this.
public final void setSelectionOverride(int rendererIndex, TrackGroupArray groups,
SelectionOverride override) {
Map overrides = selectionOverrides.get(rendererIndex);
@@ -411,13 +410,18 @@ public static final class MappedTrackInfo {
*/
public static final int RENDERER_SUPPORT_NO_TRACKS = 0;
/**
- * The renderer has associated tracks, but cannot play any of them.
+ * The renderer has associated tracks, but all are of unsupported types.
*/
- public static final int RENDERER_SUPPORT_UNPLAYABLE_TRACKS = 1;
+ public static final int RENDERER_SUPPORT_UNSUPPORTED_TRACKS = 1;
/**
- * The renderer has associated tracks, and can play at least one of them.
+ * The renderer has associated tracks and at least one is of a supported type, but all of the
+ * tracks whose types are supported exceed the renderer's capabilities.
*/
- public static final int RENDERER_SUPPORT_PLAYABLE_TRACKS = 2;
+ public static final int RENDERER_SUPPORT_EXCEEDS_CAPABILITIES_TRACKS = 2;
+ /**
+ * The renderer has associated tracks and can play at least one of them.
+ */
+ public static final int RENDERER_SUPPORT_PLAYABLE_TRACKS = 3;
/**
* The number of renderers to which tracks are mapped.
@@ -465,21 +469,49 @@ public TrackGroupArray getTrackGroups(int rendererIndex) {
*
* @param rendererIndex The renderer index.
* @return One of {@link #RENDERER_SUPPORT_PLAYABLE_TRACKS},
- * {@link #RENDERER_SUPPORT_UNPLAYABLE_TRACKS} and {@link #RENDERER_SUPPORT_NO_TRACKS}.
+ * {@link #RENDERER_SUPPORT_EXCEEDS_CAPABILITIES_TRACKS},
+ * {@link #RENDERER_SUPPORT_UNSUPPORTED_TRACKS} and {@link #RENDERER_SUPPORT_NO_TRACKS}.
*/
public int getRendererSupport(int rendererIndex) {
- boolean hasTracks = false;
+ int bestRendererSupport = RENDERER_SUPPORT_NO_TRACKS;
int[][] rendererFormatSupport = formatSupport[rendererIndex];
for (int i = 0; i < rendererFormatSupport.length; i++) {
for (int j = 0; j < rendererFormatSupport[i].length; j++) {
- hasTracks = true;
- if ((rendererFormatSupport[i][j] & RendererCapabilities.FORMAT_SUPPORT_MASK)
- == RendererCapabilities.FORMAT_HANDLED) {
- return RENDERER_SUPPORT_PLAYABLE_TRACKS;
+ int trackRendererSupport;
+ switch (rendererFormatSupport[i][j] & RendererCapabilities.FORMAT_SUPPORT_MASK) {
+ case RendererCapabilities.FORMAT_HANDLED:
+ return RENDERER_SUPPORT_PLAYABLE_TRACKS;
+ case RendererCapabilities.FORMAT_EXCEEDS_CAPABILITIES:
+ trackRendererSupport = RENDERER_SUPPORT_EXCEEDS_CAPABILITIES_TRACKS;
+ break;
+ default:
+ trackRendererSupport = RENDERER_SUPPORT_UNSUPPORTED_TRACKS;
+ break;
}
+ bestRendererSupport = Math.max(bestRendererSupport, trackRendererSupport);
}
}
- return hasTracks ? RENDERER_SUPPORT_UNPLAYABLE_TRACKS : RENDERER_SUPPORT_NO_TRACKS;
+ return bestRendererSupport;
+ }
+
+ /**
+ * Returns the best level of support obtained from {@link #getRendererSupport(int)} for all
+ * renderers of the specified track type. If no renderers exist for the specified type then
+ * {@link #RENDERER_SUPPORT_NO_TRACKS} is returned.
+ *
+ * @param trackType The track type. One of the {@link C} {@code TRACK_TYPE_*} constants.
+ * @return One of {@link #RENDERER_SUPPORT_PLAYABLE_TRACKS},
+ * {@link #RENDERER_SUPPORT_EXCEEDS_CAPABILITIES_TRACKS},
+ * {@link #RENDERER_SUPPORT_UNSUPPORTED_TRACKS} and {@link #RENDERER_SUPPORT_NO_TRACKS}.
+ */
+ public int getTrackTypeRendererSupport(int trackType) {
+ int bestRendererSupport = RENDERER_SUPPORT_NO_TRACKS;
+ for (int i = 0; i < length; i++) {
+ if (rendererTrackTypes[i] == trackType) {
+ bestRendererSupport = Math.max(bestRendererSupport, getRendererSupport(i));
+ }
+ }
+ return bestRendererSupport;
}
/**
@@ -576,25 +608,6 @@ public TrackGroupArray getUnassociatedTrackGroups() {
return unassociatedTrackGroups;
}
- /**
- * Returns true if tracks of the specified type exist and have been associated with renderers,
- * but are all unplayable. Returns false in all other cases.
- *
- * @param trackType The track type.
- * @return True if tracks of the specified type exist, if at least one renderer exists that
- * handles tracks of the specified type, and if all of the tracks if the specified type are
- * unplayable. False in all other cases.
- */
- public boolean hasOnlyUnplayableTracks(int trackType) {
- int rendererSupport = RENDERER_SUPPORT_NO_TRACKS;
- for (int i = 0; i < length; i++) {
- if (rendererTrackTypes[i] == trackType) {
- rendererSupport = Math.max(rendererSupport, getRendererSupport(i));
- }
- }
- return rendererSupport == RENDERER_SUPPORT_UNPLAYABLE_TRACKS;
- }
-
}
}