Merge "Fix checking trackId" into lmp-dev

This commit is contained in:
Chulwoo Lee
2014-08-26 02:46:40 +00:00
committed by Android (Google) Code Review

View File

@@ -1170,16 +1170,19 @@ public final class TvInputManager {
*/
public void selectTrack(int type, String trackId) {
if (type == TvTrackInfo.TYPE_AUDIO) {
if (trackId != null && !mAudioTracks.contains(trackId)) {
if (trackId != null && !containsTrack(mAudioTracks, trackId)) {
Log.w(TAG, "Invalid audio trackId: " + trackId);
return;
}
} else if (type == TvTrackInfo.TYPE_VIDEO) {
if (trackId != null && !mVideoTracks.contains(trackId)) {
if (trackId != null && !containsTrack(mVideoTracks, trackId)) {
Log.w(TAG, "Invalid video trackId: " + trackId);
return;
}
} else if (type == TvTrackInfo.TYPE_SUBTITLE) {
if (trackId != null && !mSubtitleTracks.contains(trackId)) {
if (trackId != null && !containsTrack(mSubtitleTracks, trackId)) {
Log.w(TAG, "Invalid subtitle trackId: " + trackId);
return;
}
} else {
throw new IllegalArgumentException("invalid type: " + type);
@@ -1195,6 +1198,15 @@ public final class TvInputManager {
}
}
private boolean containsTrack(List<TvTrackInfo> tracks, String trackId) {
for (TvTrackInfo track : tracks) {
if (track.getId().equals(trackId)) {
return true;
}
}
return false;
}
/**
* Returns the list of tracks for a given type. Returns {@code null} if the information is
* not available.