/** Builder for {@link ImaAdsLoader}. */ public static final class Builder { private final Context context; private @Nullable ImaSdkSettings imaSdkSettings; private @Nullable AdEventListener adEventListener; private @Nullable Set<UiElement> adUiElements; private int vastLoadTimeoutMs; private int mediaLoadTimeoutMs; private int mediaBitrate; private boolean focusSkipButtonWhenAvailable; private ImaFactory imaFactory; /** * Creates a new builder for {@link ImaAdsLoader}. * * @param context The context; */ public Builder(Context context) { this.context = Assertions.checkNotNull(context); vastLoadTimeoutMs = TIMEOUT_UNSET; mediaLoadTimeoutMs = TIMEOUT_UNSET; mediaBitrate = BITRATE_UNSET; focusSkipButtonWhenAvailable = true; imaFactory = new DefaultImaFactory(); } /** * Sets the IMA SDK settings. The provided settings instance's player type and version fields
int periodAdGroupCount = period.getAdGroupCount(); for (int adGroupIndex = 0; adGroupIndex < periodAdGroupCount; adGroupIndex++) { long adGroupTimeInPeriodUs = period.getAdGroupTimeUs(adGroupIndex); if (adGroupTimeInPeriodUs == C.TIME_END_OF_SOURCE) { if (period.durationUs == C.TIME_UNSET) { long adGroupTimeInWindowUs = adGroupTimeInPeriodUs + period.getPositionInWindowUs(); if (adGroupTimeInWindowUs >= 0 && adGroupTimeInWindowUs <= window.durationUs) { if (adGroupCount == adGroupTimesMs.length) { playedAdGroups[adGroupCount] = period.hasPlayedAdGroup(adGroupIndex); adGroupCount++;
@Override public void onTimelineChanged(Timeline timeline, Object manifest, int reason) { int periodCount = timeline.getPeriodCount(); int windowCount = timeline.getWindowCount(); Log.d(TAG, "sourceInfo [periodCount=" + periodCount + ", windowCount=" + windowCount); for (int i = 0; i < Math.min(periodCount, MAX_TIMELINE_ITEM_LINES); i++) { timeline.getPeriod(i, period); Log.d(TAG, " " + "period [" + getTimeString(period.getDurationMs()) + "]"); } if (periodCount > MAX_TIMELINE_ITEM_LINES) { Log.d(TAG, " ..."); } for (int i = 0; i < Math.min(windowCount, MAX_TIMELINE_ITEM_LINES); i++) { timeline.getWindow(i, window); Log.d(TAG, " " + "window [" + getTimeString(window.getDurationMs()) + ", " + window.isSeekable + ", " + window.isDynamic + "]"); } if (windowCount > MAX_TIMELINE_ITEM_LINES) { Log.d(TAG, " ..."); } Log.d(TAG, "]"); }
period = new Timeline.Period(); window = new Timeline.Window(); formatBuilder = new StringBuilder();
int periodAdGroupCount = period.getAdGroupCount(); for (int adGroupIndex = 0; adGroupIndex < periodAdGroupCount; adGroupIndex++) { long adGroupTimeInPeriodUs = period.getAdGroupTimeUs(adGroupIndex); if (adGroupTimeInPeriodUs == C.TIME_END_OF_SOURCE) { if (period.durationUs == C.TIME_UNSET) { long adGroupTimeInWindowUs = adGroupTimeInPeriodUs + period.getPositionInWindowUs(); if (adGroupTimeInWindowUs >= 0 && adGroupTimeInWindowUs <= window.durationUs) { if (adGroupCount == adGroupTimesMs.length) { playedAdGroups[adGroupCount] = period.hasPlayedAdGroup(adGroupIndex); adGroupCount++;
public EventLogger(MappingTrackSelector trackSelector) { this.trackSelector = trackSelector; window = new Timeline.Window(); period = new Timeline.Period(); startTimeMs = SystemClock.elapsedRealtime(); }
@Override public void onTimelineChanged(Timeline timeline, Object manifest) { int periodCount = timeline.getPeriodCount(); int windowCount = timeline.getWindowCount(); Log.d(TAG, "sourceInfo [periodCount=" + periodCount + ", windowCount=" + windowCount); for (int i = 0; i < Math.min(periodCount, MAX_TIMELINE_ITEM_LINES); i++) { timeline.getPeriod(i, period); Log.d(TAG, " " + "period [" + getTimeString(period.getDurationMs()) + "]"); } if (periodCount > MAX_TIMELINE_ITEM_LINES) { Log.d(TAG, " ..."); } for (int i = 0; i < Math.min(windowCount, MAX_TIMELINE_ITEM_LINES); i++) { timeline.getWindow(i, window); Log.d(TAG, " " + "window [" + getTimeString(window.getDurationMs()) + ", " + window.isSeekable + ", " + window.isDynamic + "]"); } if (windowCount > MAX_TIMELINE_ITEM_LINES) { Log.d(TAG, " ..."); } Log.d(TAG, "]"); }
public EventLogger(MappingTrackSelector trackSelector) { this.trackSelector = trackSelector; window = new Timeline.Window(); period = new Timeline.Period(); startTimeMs = SystemClock.elapsedRealtime(); }
if (currentPeriodId.isAd()) { int adGroupIndex = currentPeriodId.adGroupIndex; int adCountInCurrentAdGroup = period.getAdCountInAdGroup(adGroupIndex); if (adCountInCurrentAdGroup == C.LENGTH_UNSET) { return null; period.getNextAdIndexToPlay(adGroupIndex, currentPeriodId.adIndexInAdGroup); if (nextAdIndexInAdGroup < adCountInCurrentAdGroup) { return !period.isAdAvailable(adGroupIndex, nextAdIndexInAdGroup) ? null : getMediaPeriodInfoForAd( if (period.getAdGroupCount() == 1 && period.getAdGroupTimeUs(0) == 0) { Pair<Object, Long> defaultPosition = timeline.getPeriodPosition( int nextAdGroupIndex = period.getAdGroupIndexForPositionUs(mediaPeriodInfo.id.endPositionUs); if (nextAdGroupIndex == C.INDEX_UNSET) { int adIndexInAdGroup = period.getFirstAdIndexToPlay(nextAdGroupIndex); return !period.isAdAvailable(nextAdGroupIndex, adIndexInAdGroup) ? null : getMediaPeriodInfoForAd( int adGroupCount = period.getAdGroupCount(); if (adGroupCount == 0) { return null;
period = new Timeline.Period(); window = new Timeline.Window(); formatBuilder = new StringBuilder();
new TrackSelection[renderers.length], null); period = new Timeline.Period(); playbackParameters = PlaybackParameters.DEFAULT; seekParameters = SeekParameters.DEFAULT;
enabledRenderers = new Renderer[0]; window = new Timeline.Window(); period = new Timeline.Period(); trackSelector.init(/* listener= */ this, bandwidthMeter);
.isEqualTo(accumulatedPeriodCounts[accumulatedPeriodCounts.length - 1]); Window window = new Window(); Period period = new Period(); for (int i = 0; i < windowCount; i++) { timeline.getWindow(i, window, true);
.isEqualTo(accumulatedPeriodCounts[accumulatedPeriodCounts.length - 1]); Window window = new Window(); Period period = new Period(); for (int i = 0; i < windowCount; i++) { timeline.getWindow(i, window, true);
for (int i = 0; i < Math.min(periodCount, MAX_TIMELINE_ITEM_LINES); i++) { eventTime.timeline.getPeriod(i, period); logd(" " + "period [" + getTimeString(period.getDurationMs()) + "]");
mainHandler = new Handler(Looper.getMainLooper()); deferredMediaPeriodByAdMediaSource = new HashMap<>(); period = new Timeline.Period(); adGroupMediaSources = new MediaSource[0][]; adGroupTimelines = new Timeline[0][];
this.useLazyPreparation = useLazyPreparation; window = new Timeline.Window(); period = new Timeline.Period(); addMediaSources(Arrays.asList(mediaSources));
/** * Moves an item within the queue. * * @param fromIndex The index of the item to move. * @param toIndex The target index of the item in the queue. * @return Whether the item move was successful. */ public boolean moveItem(int fromIndex, int toIndex) { // Player update. concatenatingMediaSource.moveMediaSource(fromIndex, toIndex); if (currentPlayer == castPlayer && castPlayer.getPlaybackState() != Player.STATE_IDLE) { Timeline castTimeline = castPlayer.getCurrentTimeline(); int periodCount = castTimeline.getPeriodCount(); if (periodCount <= fromIndex || periodCount <= toIndex) { return false; } int elementId = (int) castTimeline.getPeriod(fromIndex, new Period()).id; castPlayer.moveItem(elementId, toIndex); } mediaQueue.add(toIndex, mediaQueue.remove(fromIndex)); // Index update. if (fromIndex == currentItemIndex) { maybeSetCurrentItemAndNotify(toIndex); } else if (fromIndex < currentItemIndex && toIndex >= currentItemIndex) { maybeSetCurrentItemAndNotify(currentItemIndex - 1); } else if (fromIndex > currentItemIndex && toIndex <= currentItemIndex) { maybeSetCurrentItemAndNotify(currentItemIndex + 1); } return true; }
/** * Resolves the specified timeline period and position to a {@link MediaPeriodId} that should be * played, returning an identifier for an ad group if one needs to be played before the specified * position, or an identifier for a content media period if not. * * @param periodUid The uid of the timeline period to play. * @param positionUs The next content position in the period to play. * @param windowSequenceNumber The sequence number of the window in the buffered sequence of * windows this period is part of. * @return The identifier for the first media period to play, taking into account unplayed ads. */ private MediaPeriodId resolveMediaPeriodIdForAds( Object periodUid, long positionUs, long windowSequenceNumber) { timeline.getPeriodByUid(periodUid, period); int adGroupIndex = period.getAdGroupIndexForPositionUs(positionUs); if (adGroupIndex == C.INDEX_UNSET) { int nextAdGroupIndex = period.getAdGroupIndexAfterPositionUs(positionUs); long endPositionUs = nextAdGroupIndex == C.INDEX_UNSET ? C.TIME_END_OF_SOURCE : period.getAdGroupTimeUs(nextAdGroupIndex); return new MediaPeriodId(periodUid, windowSequenceNumber, endPositionUs); } else { int adIndexInAdGroup = period.getFirstAdIndexToPlay(adGroupIndex); return new MediaPeriodId(periodUid, adGroupIndex, adIndexInAdGroup, windowSequenceNumber); } }
/** * Removes the item at the given index from the media queue. * * @param itemIndex The index of the item to remove. * @return Whether the removal was successful. */ public boolean removeItem(int itemIndex) { concatenatingMediaSource.removeMediaSource(itemIndex); if (currentPlayer == castPlayer) { if (castPlayer.getPlaybackState() != Player.STATE_IDLE) { Timeline castTimeline = castPlayer.getCurrentTimeline(); if (castTimeline.getPeriodCount() <= itemIndex) { return false; } castPlayer.removeItem((int) castTimeline.getPeriod(itemIndex, new Period()).id); } } mediaQueue.remove(itemIndex); if (itemIndex == currentItemIndex && itemIndex == mediaQueue.size()) { maybeSetCurrentItemAndNotify(C.INDEX_UNSET); } else if (itemIndex < currentItemIndex) { maybeSetCurrentItemAndNotify(currentItemIndex - 1); } return true; }