Skip to content

Commit

Permalink
Allow the app to specify extra ad markers
Browse files Browse the repository at this point in the history
Issue: #3184

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=165895259
  • Loading branch information
andrewlewis authored and ojw28 committed Aug 22, 2017
1 parent 9a9bb21 commit cec0c52
Showing 1 changed file with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.os.SystemClock;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.LayoutInflater;
Expand Down Expand Up @@ -311,6 +312,8 @@ public boolean dispatchSetRepeatMode(Player player, @RepeatMode int repeatMode)
private long hideAtMs;
private long[] adGroupTimesMs;
private boolean[] playedAdGroups;
private long[] extraAdGroupTimesMs;
private boolean[] extraPlayedAdGroups;

private final Runnable updateProgressAction = new Runnable() {
@Override
Expand Down Expand Up @@ -363,6 +366,8 @@ public PlaybackControlView(Context context, AttributeSet attrs, int defStyleAttr
formatter = new Formatter(formatBuilder, Locale.getDefault());
adGroupTimesMs = new long[0];
playedAdGroups = new boolean[0];
extraAdGroupTimesMs = new long[0];
extraPlayedAdGroups = new boolean[0];
componentListener = new ComponentListener();
controlDispatcher = DEFAULT_CONTROL_DISPATCHER;

Expand Down Expand Up @@ -461,6 +466,29 @@ public void setShowMultiWindowTimeBar(boolean showMultiWindowTimeBar) {
updateTimeBarMode();
}

/**
* Sets the millisecond positions of extra ad markers relative to the start of the window (or
* timeline, if in multi-window mode) and whether each extra ad has been played or not. The
* markers are shown in addition to any ad markers for ads in the player's timeline.
*
* @param extraAdGroupTimesMs The millisecond timestamps of the extra ad markers to show, or
* {@code null} to show no extra ad markers.
* @param extraPlayedAdGroups Whether each ad has been played, or {@code null} to show no extra ad
* markers.
*/
public void setExtraAdGroupMarkers(@Nullable long[] extraAdGroupTimesMs,
@Nullable boolean[] extraPlayedAdGroups) {
if (extraAdGroupTimesMs == null) {
this.extraAdGroupTimesMs = new long[0];
this.extraPlayedAdGroups = new boolean[0];
} else {
Assertions.checkArgument(extraAdGroupTimesMs.length == extraPlayedAdGroups.length);
this.extraAdGroupTimesMs = extraAdGroupTimesMs;
this.extraPlayedAdGroups = extraPlayedAdGroups;
}
updateProgress();
}

/**
* Sets the {@link VisibilityListener}.
*
Expand Down Expand Up @@ -767,7 +795,15 @@ private void updateProgress() {
bufferedPosition += player.getBufferedPosition();
}
if (timeBar != null) {
timeBar.setAdGroupTimesMs(adGroupTimesMs, playedAdGroups, adGroupCount);
int extraAdGroupCount = extraAdGroupTimesMs.length;
int totalAdGroupCount = adGroupCount + extraAdGroupCount;
if (totalAdGroupCount > adGroupTimesMs.length) {
adGroupTimesMs = Arrays.copyOf(adGroupTimesMs, totalAdGroupCount);
playedAdGroups = Arrays.copyOf(playedAdGroups, totalAdGroupCount);
}
System.arraycopy(extraAdGroupTimesMs, 0, adGroupTimesMs, adGroupCount, extraAdGroupCount);
System.arraycopy(extraPlayedAdGroups, 0, playedAdGroups, adGroupCount, extraAdGroupCount);
timeBar.setAdGroupTimesMs(adGroupTimesMs, playedAdGroups, totalAdGroupCount);
}
}
if (durationView != null) {
Expand Down

0 comments on commit cec0c52

Please sign in to comment.