Skip to content

Commit

Permalink
Constraint seeks within bounds for ConstantBitrateSeeker
Browse files Browse the repository at this point in the history
We do this everywhere for index based seeking already.

Issue: google#2876

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=157568788
  • Loading branch information
ojw28 committed Jun 6, 2017
1 parent 854c8d0 commit c80b60f
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.google.android.exoplayer2.extractor.mp3;

import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.util.Util;

/**
* MP3 seeker that doesn't rely on metadata and seeks assuming the source has a constant bitrate.
Expand All @@ -41,8 +42,11 @@ public boolean isSeekable() {

@Override
public long getPosition(long timeUs) {
return durationUs == C.TIME_UNSET ? 0
: firstFramePosition + (timeUs * bitrate) / (C.MICROS_PER_SECOND * BITS_PER_BYTE);
if (durationUs == C.TIME_UNSET) {
return 0;
}
timeUs = Util.constrainValue(timeUs, 0, durationUs);
return firstFramePosition + (timeUs * bitrate) / (C.MICROS_PER_SECOND * BITS_PER_BYTE);
}

@Override
Expand Down

0 comments on commit c80b60f

Please sign in to comment.