mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Allow the app to specify extra ad markers
Issue: #3184 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=165895259
This commit is contained in:
parent
9a9bb2192c
commit
cec0c52c8d
@ -21,6 +21,7 @@ import android.content.res.Resources;
|
||||
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;
|
||||
@ -311,6 +312,8 @@ public class PlaybackControlView extends FrameLayout {
|
||||
private long hideAtMs;
|
||||
private long[] adGroupTimesMs;
|
||||
private boolean[] playedAdGroups;
|
||||
private long[] extraAdGroupTimesMs;
|
||||
private boolean[] extraPlayedAdGroups;
|
||||
|
||||
private final Runnable updateProgressAction = new Runnable() {
|
||||
@Override
|
||||
@ -363,6 +366,8 @@ public class PlaybackControlView extends FrameLayout {
|
||||
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;
|
||||
|
||||
@ -461,6 +466,29 @@ public class PlaybackControlView extends FrameLayout {
|
||||
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}.
|
||||
*
|
||||
@ -767,7 +795,15 @@ public class PlaybackControlView extends FrameLayout {
|
||||
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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user