Prevent seeking out of video duration in player

This commit is contained in:
Stypox 2020-09-09 20:41:30 +02:00
parent 1605e50cef
commit 52e89c1d1c
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23
1 changed files with 9 additions and 1 deletions

View File

@ -1242,7 +1242,15 @@ public abstract class BasePlayer implements
Log.d(TAG, "seekBy() called with: position = [" + positionMillis + "]");
}
if (simpleExoPlayer != null) {
simpleExoPlayer.seekTo(positionMillis);
// prevent invalid positions when fast-forwarding/-rewinding
long normalizedPositionMillis = positionMillis;
if (normalizedPositionMillis < 0) {
normalizedPositionMillis = 0;
} else if (normalizedPositionMillis > simpleExoPlayer.getDuration()) {
normalizedPositionMillis = simpleExoPlayer.getDuration();
}
simpleExoPlayer.seekTo(normalizedPositionMillis);
}
}