Skip to content

Commit

Permalink
Ensure the SilenceMediaSource position is in range
Browse files Browse the repository at this point in the history
Issue: google#6229
PiperOrigin-RevId: 260500986
  • Loading branch information
andrewlewis authored and Oliver Woodman committed Jul 29, 2019
1 parent d279c3d commit f5980a5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
([#6153](https://github.com/google/ExoPlayer/issues/6153)).
* Fix `DataSchemeDataSource` re-opening and range requests
([#6192](https://github.com/google/ExoPlayer/issues/6192)).
* Ensure the `SilenceMediaSource` position is in range
([#6229](https://github.com/google/ExoPlayer/issues/6229)).
* Flac extension: Parse `VORBIS_COMMENT` metadata
([#5527](https://github.com/google/ExoPlayer/issues/5527)).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public long selectTracks(
@NullableType SampleStream[] streams,
boolean[] streamResetFlags,
long positionUs) {
positionUs = constrainSeekPosition(positionUs);
for (int i = 0; i < selections.length; i++) {
if (streams[i] != null && (selections[i] == null || !mayRetainStreamFlags[i])) {
sampleStreams.remove(streams[i]);
Expand All @@ -144,6 +145,7 @@ public long readDiscontinuity() {

@Override
public long seekToUs(long positionUs) {
positionUs = constrainSeekPosition(positionUs);
for (int i = 0; i < sampleStreams.size(); i++) {
((SilenceSampleStream) sampleStreams.get(i)).seekTo(positionUs);
}
Expand All @@ -152,7 +154,7 @@ public long seekToUs(long positionUs) {

@Override
public long getAdjustedSeekPositionUs(long positionUs, SeekParameters seekParameters) {
return positionUs;
return constrainSeekPosition(positionUs);
}

@Override
Expand All @@ -172,6 +174,10 @@ public boolean continueLoading(long positionUs) {

@Override
public void reevaluateBuffer(long positionUs) {}

private long constrainSeekPosition(long positionUs) {
return Util.constrainValue(positionUs, 0, durationUs);
}
}

private static final class SilenceSampleStream implements SampleStream {
Expand All @@ -187,7 +193,7 @@ public SilenceSampleStream(long durationUs) {
}

public void seekTo(long positionUs) {
positionBytes = getAudioByteCount(positionUs);
positionBytes = Util.constrainValue(getAudioByteCount(positionUs), 0, durationBytes);
}

@Override
Expand Down

0 comments on commit f5980a5

Please sign in to comment.