mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
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
This commit is contained in:
parent
a0aa9a3803
commit
4180b9656d
4 changed files with 33 additions and 13 deletions
|
|
@ -76,6 +76,7 @@ public class DefaultTimeBar extends View implements TimeBar {
|
||||||
private final Paint bufferedPaint;
|
private final Paint bufferedPaint;
|
||||||
private final Paint unplayedPaint;
|
private final Paint unplayedPaint;
|
||||||
private final Paint adMarkerPaint;
|
private final Paint adMarkerPaint;
|
||||||
|
private final Paint playedAdMarkerPaint;
|
||||||
private final Paint scrubberPaint;
|
private final Paint scrubberPaint;
|
||||||
private final int barHeight;
|
private final int barHeight;
|
||||||
private final int touchTargetHeight;
|
private final int touchTargetHeight;
|
||||||
|
|
@ -103,6 +104,7 @@ public class DefaultTimeBar extends View implements TimeBar {
|
||||||
private long bufferedPosition;
|
private long bufferedPosition;
|
||||||
private int adGroupCount;
|
private int adGroupCount;
|
||||||
private long[] adGroupTimesMs;
|
private long[] adGroupTimesMs;
|
||||||
|
private boolean[] playedAdGroups;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new time bar.
|
* Creates a new time bar.
|
||||||
|
|
@ -117,6 +119,7 @@ public class DefaultTimeBar extends View implements TimeBar {
|
||||||
bufferedPaint = new Paint();
|
bufferedPaint = new Paint();
|
||||||
unplayedPaint = new Paint();
|
unplayedPaint = new Paint();
|
||||||
adMarkerPaint = new Paint();
|
adMarkerPaint = new Paint();
|
||||||
|
playedAdMarkerPaint = new Paint();
|
||||||
scrubberPaint = new Paint();
|
scrubberPaint = new Paint();
|
||||||
scrubberPaint.setAntiAlias(true);
|
scrubberPaint.setAntiAlias(true);
|
||||||
|
|
||||||
|
|
@ -155,11 +158,14 @@ public class DefaultTimeBar extends View implements TimeBar {
|
||||||
getDefaultUnplayedColor(playedColor));
|
getDefaultUnplayedColor(playedColor));
|
||||||
int adMarkerColor = a.getInt(R.styleable.DefaultTimeBar_ad_marker_color,
|
int adMarkerColor = a.getInt(R.styleable.DefaultTimeBar_ad_marker_color,
|
||||||
DEFAULT_AD_MARKER_COLOR);
|
DEFAULT_AD_MARKER_COLOR);
|
||||||
|
int playedAdMarkerColor = a.getInt(R.styleable.DefaultTimeBar_played_ad_marker_color,
|
||||||
|
getDefaultPlayedAdMarkerColor(adMarkerColor));
|
||||||
playedPaint.setColor(playedColor);
|
playedPaint.setColor(playedColor);
|
||||||
scrubberPaint.setColor(scrubberColor);
|
scrubberPaint.setColor(scrubberColor);
|
||||||
bufferedPaint.setColor(bufferedColor);
|
bufferedPaint.setColor(bufferedColor);
|
||||||
unplayedPaint.setColor(unplayedColor);
|
unplayedPaint.setColor(unplayedColor);
|
||||||
adMarkerPaint.setColor(adMarkerColor);
|
adMarkerPaint.setColor(adMarkerColor);
|
||||||
|
playedAdMarkerPaint.setColor(playedAdMarkerColor);
|
||||||
} finally {
|
} finally {
|
||||||
a.recycle();
|
a.recycle();
|
||||||
}
|
}
|
||||||
|
|
@ -238,10 +244,13 @@ public class DefaultTimeBar extends View implements TimeBar {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setAdGroupTimesMs(@Nullable long[] adGroupTimesMs, int adGroupCount) {
|
public void setAdGroupTimesMs(@Nullable long[] adGroupTimesMs, @Nullable boolean[] playedAdGroups,
|
||||||
Assertions.checkArgument(adGroupCount == 0 || adGroupTimesMs != null);
|
int adGroupCount) {
|
||||||
|
Assertions.checkArgument(adGroupCount == 0
|
||||||
|
|| (adGroupTimesMs != null && playedAdGroups != null));
|
||||||
this.adGroupCount = adGroupCount;
|
this.adGroupCount = adGroupCount;
|
||||||
this.adGroupTimesMs = adGroupTimesMs;
|
this.adGroupTimesMs = adGroupTimesMs;
|
||||||
|
this.playedAdGroups = playedAdGroups;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -524,7 +533,8 @@ public class DefaultTimeBar extends View implements TimeBar {
|
||||||
(int) (progressBar.width() * adGroupTimeMs / duration) - adMarkerOffset;
|
(int) (progressBar.width() * adGroupTimeMs / duration) - adMarkerOffset;
|
||||||
int markerLeft = progressBar.left + Math.min(progressBar.width() - adMarkerWidth,
|
int markerLeft = progressBar.left + Math.min(progressBar.width() - adMarkerWidth,
|
||||||
Math.max(0, markerPositionOffset));
|
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);
|
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 @RepeatToggleModes int repeatToggleModes;
|
||||||
private long hideAtMs;
|
private long hideAtMs;
|
||||||
private long[] adGroupTimesMs;
|
private long[] adGroupTimesMs;
|
||||||
|
private boolean[] playedAdGroups;
|
||||||
|
|
||||||
private final Runnable updateProgressAction = new Runnable() {
|
private final Runnable updateProgressAction = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -364,6 +365,7 @@ public class PlaybackControlView extends FrameLayout {
|
||||||
formatBuilder = new StringBuilder();
|
formatBuilder = new StringBuilder();
|
||||||
formatter = new Formatter(formatBuilder, Locale.getDefault());
|
formatter = new Formatter(formatBuilder, Locale.getDefault());
|
||||||
adGroupTimesMs = new long[0];
|
adGroupTimesMs = new long[0];
|
||||||
|
playedAdGroups = new boolean[0];
|
||||||
componentListener = new ComponentListener();
|
componentListener = new ComponentListener();
|
||||||
controlDispatcher = DEFAULT_CONTROL_DISPATCHER;
|
controlDispatcher = DEFAULT_CONTROL_DISPATCHER;
|
||||||
|
|
||||||
|
|
@ -724,10 +726,6 @@ public class PlaybackControlView extends FrameLayout {
|
||||||
}
|
}
|
||||||
for (int adGroupIndex = 0; adGroupIndex < period.getAdGroupCount(); adGroupIndex++) {
|
for (int adGroupIndex = 0; adGroupIndex < period.getAdGroupCount(); adGroupIndex++) {
|
||||||
long adGroupTimeUs = period.getAdGroupTimeUs(adGroupIndex);
|
long adGroupTimeUs = period.getAdGroupTimeUs(adGroupIndex);
|
||||||
if (period.hasPlayedAdGroup(adGroupIndex)) {
|
|
||||||
// Don't show played ad groups.
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (adGroupTimeUs == C.TIME_END_OF_SOURCE) {
|
if (adGroupTimeUs == C.TIME_END_OF_SOURCE) {
|
||||||
adGroupTimeUs = periodDurationUs;
|
adGroupTimeUs = periodDurationUs;
|
||||||
}
|
}
|
||||||
|
|
@ -736,10 +734,13 @@ public class PlaybackControlView extends FrameLayout {
|
||||||
}
|
}
|
||||||
if (adGroupTimeUs >= 0 && adGroupTimeUs <= window.durationUs) {
|
if (adGroupTimeUs >= 0 && adGroupTimeUs <= window.durationUs) {
|
||||||
if (adGroupTimesMsCount == adGroupTimesMs.length) {
|
if (adGroupTimesMsCount == adGroupTimesMs.length) {
|
||||||
adGroupTimesMs = Arrays.copyOf(adGroupTimesMs,
|
int newLength = adGroupTimesMs.length == 0 ? 1 : adGroupTimesMs.length * 2;
|
||||||
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) {
|
if (i < periodIndex) {
|
||||||
|
|
@ -757,7 +758,7 @@ public class PlaybackControlView extends FrameLayout {
|
||||||
bufferedPosition += player.getBufferedPosition();
|
bufferedPosition += player.getBufferedPosition();
|
||||||
}
|
}
|
||||||
if (timeBar != null) {
|
if (timeBar != null) {
|
||||||
timeBar.setAdGroupTimesMs(adGroupTimesMs, adGroupTimesMsCount);
|
timeBar.setAdGroupTimesMs(adGroupTimesMs, playedAdGroups, adGroupTimesMsCount);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
position = player.getCurrentPosition();
|
position = player.getCurrentPosition();
|
||||||
|
|
|
||||||
|
|
@ -78,13 +78,17 @@ public interface TimeBar {
|
||||||
void setDuration(long duration);
|
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
|
* @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.
|
* 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.
|
* @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.
|
* Listener for scrubbing events.
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,7 @@
|
||||||
<attr name="buffered_color" format="color"/>
|
<attr name="buffered_color" format="color"/>
|
||||||
<attr name="unplayed_color" format="color"/>
|
<attr name="unplayed_color" format="color"/>
|
||||||
<attr name="ad_marker_color" format="color"/>
|
<attr name="ad_marker_color" format="color"/>
|
||||||
|
<attr name="played_ad_marker_color" format="color"/>
|
||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue