Fix playback position indicator for trimmed video clips.

This commit is contained in:
Nicholas Tinsley
2024-08-08 14:40:21 -04:00
committed by mtang-signal
parent 1d6917476e
commit 4af6e0480a
2 changed files with 12 additions and 5 deletions

View File

@@ -288,9 +288,15 @@ public class VideoPlayer extends FrameLayout {
return 0L;
}
public long getPlaybackPositionUs() {
/**
* After calling {@link #setPlaybackPosition}, the underlying {@link Player} resets the current position to 0.
* We manually store the offset of where we clipped to, and add that here.
*
* @return the current playback position, rounded to the nearest millisecond
*/
public long getTruePlaybackPosition() {
if (this.exoPlayer != null) {
return TimeUnit.MILLISECONDS.toMicros(this.exoPlayer.getCurrentPosition());
return this.exoPlayer.getCurrentPosition() + Math.round(clippedStartUs / 1000.0);
}
return -1L;
}