Correctly bound search into segment indices.

The return value here assumed that the time being searched for
was beyond the start time of the last segment. This fix also
handles the case where the time is prior to the start of the
first segment.
This commit is contained in:
Oliver Woodman 2015-02-25 13:34:31 +00:00
parent d2da3bbf8a
commit 2ce17b601f

View File

@ -148,7 +148,8 @@ public abstract class SegmentBase {
* @see DashSegmentIndex#getSegmentNum(long)
*/
public int getSegmentNum(long timeUs) {
int lowIndex = getFirstSegmentNum();
final int firstSegmentNum = getFirstSegmentNum();
int lowIndex = firstSegmentNum;
int highIndex = getLastSegmentNum();
if (segmentTimeline == null) {
// All segments are of equal duration (with the possible exception of the last one).
@ -171,7 +172,7 @@ public abstract class SegmentBase {
return midIndex;
}
}
return lowIndex - 1;
return lowIndex == firstSegmentNum ? lowIndex : highIndex;
}
}