Commit 0f9d9d56 by tonihei Committed by Oliver Woodman

Fix scrub seek position estimation for multi window time bar.

When using a multi window time bar, the onScrubStop method uses another
method to estimate the seek position than the updateProgress method for
rendering the time bar. If the time line contains windows starting with an
ad period followed by other content, they differ in their behaviour.
 - updateProgress checks all periods and leaves out all ad periods
 - onScrubStop only checks windows and leaves them out when the first
   period is an ad.

Changed onScrubStop to fit approach in updateProgess.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=154271628
parent f9c37423
...@@ -728,6 +728,42 @@ public class PlaybackControlView extends FrameLayout { ...@@ -728,6 +728,42 @@ public class PlaybackControlView extends FrameLayout {
} }
} }
private void seekToTimebarPosition(long timebarPositionMs) {
if (multiWindowTimeBar) {
Timeline timeline = player.getCurrentTimeline();
int windowCount = timeline.getWindowCount();
long remainingMs = timebarPositionMs;
for (int i = 0; i < windowCount; i++) {
timeline.getWindow(i, window);
for (int j = window.firstPeriodIndex; j <= window.lastPeriodIndex; j++) {
if (!timeline.getPeriod(j, period).isAd) {
long periodDurationMs = period.getDurationMs();
if (periodDurationMs == C.TIME_UNSET) {
// Should never happen as canShowMultiWindowTimeBar is true.
throw new IllegalStateException();
}
if (j == window.firstPeriodIndex) {
periodDurationMs -= window.getPositionInFirstPeriodMs();
}
if (i == windowCount - 1 && j == window.lastPeriodIndex
&& remainingMs >= periodDurationMs) {
// Seeking past the end of the last window should seek to the end of the timeline.
seekTo(i, window.getDurationMs());
return;
}
if (remainingMs < periodDurationMs) {
seekTo(i, period.getPositionInWindowMs() + remainingMs);
return;
}
remainingMs -= periodDurationMs;
}
}
}
} else {
seekTo(timebarPositionMs);
}
}
@Override @Override
public void onAttachedToWindow() { public void onAttachedToWindow() {
super.onAttachedToWindow(); super.onAttachedToWindow();
...@@ -855,32 +891,7 @@ public class PlaybackControlView extends FrameLayout { ...@@ -855,32 +891,7 @@ public class PlaybackControlView extends FrameLayout {
public void onScrubStop(TimeBar timeBar, long position, boolean canceled) { public void onScrubStop(TimeBar timeBar, long position, boolean canceled) {
scrubbing = false; scrubbing = false;
if (!canceled && player != null) { if (!canceled && player != null) {
if (multiWindowTimeBar) { seekToTimebarPosition(position);
Timeline timeline = player.getCurrentTimeline();
int windowCount = timeline.getWindowCount();
long remainingMs = position;
for (int i = 0; i < windowCount; i++) {
timeline.getWindow(i, window);
if (!timeline.getPeriod(window.firstPeriodIndex, period).isAd) {
long windowDurationMs = window.getDurationMs();
if (windowDurationMs == C.TIME_UNSET) {
break;
}
if (i == windowCount - 1 && remainingMs >= windowDurationMs) {
// Seeking past the end of the last window should seek to the end of the timeline.
seekTo(i, windowDurationMs);
break;
}
if (remainingMs < windowDurationMs) {
seekTo(i, remainingMs);
break;
}
remainingMs -= windowDurationMs;
}
}
} else {
seekTo(position);
}
} }
hideAfterTimeout(); hideAfterTimeout();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment