Commit 4180b965 by andrewlewis Committed by Oliver Woodman

Show played ad groups

By default played ad groups are shown faded out. This helps the user know
whether they will see an ad when they seek to a given position.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=161098491
parent a0aa9a38
......@@ -76,6 +76,7 @@ public class DefaultTimeBar extends View implements TimeBar {
private final Paint bufferedPaint;
private final Paint unplayedPaint;
private final Paint adMarkerPaint;
private final Paint playedAdMarkerPaint;
private final Paint scrubberPaint;
private final int barHeight;
private final int touchTargetHeight;
......@@ -103,6 +104,7 @@ public class DefaultTimeBar extends View implements TimeBar {
private long bufferedPosition;
private int adGroupCount;
private long[] adGroupTimesMs;
private boolean[] playedAdGroups;
/**
* Creates a new time bar.
......@@ -117,6 +119,7 @@ public class DefaultTimeBar extends View implements TimeBar {
bufferedPaint = new Paint();
unplayedPaint = new Paint();
adMarkerPaint = new Paint();
playedAdMarkerPaint = new Paint();
scrubberPaint = new Paint();
scrubberPaint.setAntiAlias(true);
......@@ -155,11 +158,14 @@ public class DefaultTimeBar extends View implements TimeBar {
getDefaultUnplayedColor(playedColor));
int adMarkerColor = a.getInt(R.styleable.DefaultTimeBar_ad_marker_color,
DEFAULT_AD_MARKER_COLOR);
int playedAdMarkerColor = a.getInt(R.styleable.DefaultTimeBar_played_ad_marker_color,
getDefaultPlayedAdMarkerColor(adMarkerColor));
playedPaint.setColor(playedColor);
scrubberPaint.setColor(scrubberColor);
bufferedPaint.setColor(bufferedColor);
unplayedPaint.setColor(unplayedColor);
adMarkerPaint.setColor(adMarkerColor);
playedAdMarkerPaint.setColor(playedAdMarkerColor);
} finally {
a.recycle();
}
......@@ -238,10 +244,13 @@ public class DefaultTimeBar extends View implements TimeBar {
}
@Override
public void setAdGroupTimesMs(@Nullable long[] adGroupTimesMs, int adGroupCount) {
Assertions.checkArgument(adGroupCount == 0 || adGroupTimesMs != null);
public void setAdGroupTimesMs(@Nullable long[] adGroupTimesMs, @Nullable boolean[] playedAdGroups,
int adGroupCount) {
Assertions.checkArgument(adGroupCount == 0
|| (adGroupTimesMs != null && playedAdGroups != null));
this.adGroupCount = adGroupCount;
this.adGroupTimesMs = adGroupTimesMs;
this.playedAdGroups = playedAdGroups;
update();
}
......@@ -524,7 +533,8 @@ public class DefaultTimeBar extends View implements TimeBar {
(int) (progressBar.width() * adGroupTimeMs / duration) - adMarkerOffset;
int markerLeft = progressBar.left + Math.min(progressBar.width() - adMarkerWidth,
Math.max(0, markerPositionOffset));
canvas.drawRect(markerLeft, barTop, markerLeft + adMarkerWidth, barBottom, adMarkerPaint);
Paint paint = playedAdGroups[i] ? playedAdMarkerPaint : adMarkerPaint;
canvas.drawRect(markerLeft, barTop, markerLeft + adMarkerWidth, barBottom, paint);
}
}
......@@ -590,4 +600,8 @@ public class DefaultTimeBar extends View implements TimeBar {
return 0xCC000000 | (playedColor & 0x00FFFFFF);
}
private static int getDefaultPlayedAdMarkerColor(int adMarkerColor) {
return 0x33000000 | (adMarkerColor & 0x00FFFFFF);
}
}
......@@ -313,6 +313,7 @@ public class PlaybackControlView extends FrameLayout {
private @RepeatToggleModes int repeatToggleModes;
private long hideAtMs;
private long[] adGroupTimesMs;
private boolean[] playedAdGroups;
private final Runnable updateProgressAction = new Runnable() {
@Override
......@@ -364,6 +365,7 @@ public class PlaybackControlView extends FrameLayout {
formatBuilder = new StringBuilder();
formatter = new Formatter(formatBuilder, Locale.getDefault());
adGroupTimesMs = new long[0];
playedAdGroups = new boolean[0];
componentListener = new ComponentListener();
controlDispatcher = DEFAULT_CONTROL_DISPATCHER;
......@@ -724,10 +726,6 @@ public class PlaybackControlView extends FrameLayout {
}
for (int adGroupIndex = 0; adGroupIndex < period.getAdGroupCount(); adGroupIndex++) {
long adGroupTimeUs = period.getAdGroupTimeUs(adGroupIndex);
if (period.hasPlayedAdGroup(adGroupIndex)) {
// Don't show played ad groups.
continue;
}
if (adGroupTimeUs == C.TIME_END_OF_SOURCE) {
adGroupTimeUs = periodDurationUs;
}
......@@ -736,10 +734,13 @@ public class PlaybackControlView extends FrameLayout {
}
if (adGroupTimeUs >= 0 && adGroupTimeUs <= window.durationUs) {
if (adGroupTimesMsCount == adGroupTimesMs.length) {
adGroupTimesMs = Arrays.copyOf(adGroupTimesMs,
adGroupTimesMs.length == 0 ? 1 : adGroupTimesMs.length * 2);
int newLength = adGroupTimesMs.length == 0 ? 1 : adGroupTimesMs.length * 2;
adGroupTimesMs = Arrays.copyOf(adGroupTimesMs, newLength);
playedAdGroups = Arrays.copyOf(playedAdGroups, newLength);
}
adGroupTimesMs[adGroupTimesMsCount++] = C.usToMs(durationUs + adGroupTimeUs);
adGroupTimesMs[adGroupTimesMsCount] = C.usToMs(durationUs + adGroupTimeUs);
playedAdGroups[adGroupTimesMsCount] = period.hasPlayedAdGroup(adGroupIndex);
adGroupTimesMsCount++;
}
}
if (i < periodIndex) {
......@@ -757,7 +758,7 @@ public class PlaybackControlView extends FrameLayout {
bufferedPosition += player.getBufferedPosition();
}
if (timeBar != null) {
timeBar.setAdGroupTimesMs(adGroupTimesMs, adGroupTimesMsCount);
timeBar.setAdGroupTimesMs(adGroupTimesMs, playedAdGroups, adGroupTimesMsCount);
}
} else {
position = player.getCurrentPosition();
......
......@@ -78,13 +78,17 @@ public interface TimeBar {
void setDuration(long duration);
/**
* Sets the times of ad groups.
* Sets the times of ad groups and whether each ad group has been played.
*
* @param adGroupTimesMs An array where the first {@code adGroupCount} elements are the times of
* ad groups in milliseconds. May be {@code null} if there are no ad groups.
* @param playedAdGroups An array where the first {@code adGroupCount} elements indicate whether
* the corresponding ad groups have been played. May be {@code null} if there are no ad
* groups.
* @param adGroupCount The number of ad groups.
*/
void setAdGroupTimesMs(@Nullable long[] adGroupTimesMs, int adGroupCount);
void setAdGroupTimesMs(@Nullable long[] adGroupTimesMs, @Nullable boolean[] playedAdGroups,
int adGroupCount);
/**
* Listener for scrubbing events.
......
......@@ -79,6 +79,7 @@
<attr name="buffered_color" format="color"/>
<attr name="unplayed_color" format="color"/>
<attr name="ad_marker_color" format="color"/>
<attr name="played_ad_marker_color" format="color"/>
</declare-styleable>
</resources>
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