use of com.google.ads.interactivemedia.v3.api.AdsManager in project ExoPlayer by google.
the class AdTagLoader method maybeInitializeAdsManager.
private void maybeInitializeAdsManager(long contentPositionMs, long contentDurationMs) {
@Nullable AdsManager adsManager = this.adsManager;
if (!isAdsManagerInitialized && adsManager != null) {
isAdsManagerInitialized = true;
@Nullable AdsRenderingSettings adsRenderingSettings = setupAdsRendering(contentPositionMs, contentDurationMs);
if (adsRenderingSettings == null) {
// There are no ads to play.
destroyAdsManager();
} else {
adsManager.init(adsRenderingSettings);
adsManager.start();
if (configuration.debugModeEnabled) {
Log.d(TAG, "Initialized with ads rendering settings: " + adsRenderingSettings);
}
}
updateAdPlaybackState();
}
}
use of com.google.ads.interactivemedia.v3.api.AdsManager in project ExoPlayer by google.
the class AdTagLoader method deactivate.
/**
* Deactivates playback.
*/
public void deactivate() {
Player player = checkNotNull(this.player);
if (!AdPlaybackState.NONE.equals(adPlaybackState) && imaPausedContent) {
if (adsManager != null) {
adsManager.pause();
}
adPlaybackState = adPlaybackState.withAdResumePositionUs(playingAd ? Util.msToUs(player.getCurrentPosition()) : 0);
}
lastVolumePercent = getPlayerVolumePercent();
lastAdProgress = getAdVideoProgressUpdate();
lastContentProgress = getContentVideoProgressUpdate();
player.removeListener(this);
this.player = null;
}
use of com.google.ads.interactivemedia.v3.api.AdsManager in project ExoPlayer by google.
the class AdTagLoader method handleTimelineOrPositionChanged.
private void handleTimelineOrPositionChanged() {
@Nullable Player player = this.player;
if (adsManager == null || player == null) {
return;
}
if (!playingAd && !player.isPlayingAd()) {
ensureSentContentCompleteIfAtEndOfStream();
if (!sentContentComplete && !timeline.isEmpty()) {
long positionMs = getContentPeriodPositionMs(player, timeline, period);
timeline.getPeriod(player.getCurrentPeriodIndex(), period);
int newAdGroupIndex = period.getAdGroupIndexForPositionUs(Util.msToUs(positionMs));
if (newAdGroupIndex != C.INDEX_UNSET) {
sentPendingContentPositionMs = false;
pendingContentPositionMs = positionMs;
}
}
}
boolean wasPlayingAd = playingAd;
int oldPlayingAdIndexInAdGroup = playingAdIndexInAdGroup;
playingAd = player.isPlayingAd();
playingAdIndexInAdGroup = playingAd ? player.getCurrentAdIndexInAdGroup() : C.INDEX_UNSET;
boolean adFinished = wasPlayingAd && playingAdIndexInAdGroup != oldPlayingAdIndexInAdGroup;
if (adFinished) {
// IMA is waiting for the ad playback to finish so invoke the callback now.
// Either CONTENT_RESUME_REQUESTED will be passed next, or playAd will be called again.
@Nullable AdMediaInfo adMediaInfo = imaAdMediaInfo;
if (adMediaInfo == null) {
Log.w(TAG, "onEnded without ad media info");
} else {
@Nullable AdInfo adInfo = adInfoByAdMediaInfo.get(adMediaInfo);
if (playingAdIndexInAdGroup == C.INDEX_UNSET || (adInfo != null && adInfo.adIndexInAdGroup < playingAdIndexInAdGroup)) {
for (int i = 0; i < adCallbacks.size(); i++) {
adCallbacks.get(i).onEnded(adMediaInfo);
}
if (configuration.debugModeEnabled) {
Log.d(TAG, "VideoAdPlayerCallback.onEnded in onTimelineChanged/onPositionDiscontinuity");
}
}
}
}
if (!sentContentComplete && !wasPlayingAd && playingAd && imaAdState == IMA_AD_STATE_NONE) {
AdPlaybackState.AdGroup adGroup = adPlaybackState.getAdGroup(player.getCurrentAdGroupIndex());
if (adGroup.timeUs == C.TIME_END_OF_SOURCE) {
sendContentComplete();
} else {
// IMA hasn't called playAd yet, so fake the content position.
fakeContentProgressElapsedRealtimeMs = SystemClock.elapsedRealtime();
fakeContentProgressOffsetMs = Util.usToMs(adGroup.timeUs);
if (fakeContentProgressOffsetMs == C.TIME_END_OF_SOURCE) {
fakeContentProgressOffsetMs = contentDurationMs;
}
}
}
}
use of com.google.ads.interactivemedia.v3.api.AdsManager in project android-player-samples by BrightcoveOS.
the class MainActivity method setupAdMarkers.
/*
This methods show how to the the Google IMA AdsManager, get the cue points and add the markers
to the Brightcove Seek Bar.
*/
private void setupAdMarkers(BaseVideoView videoView) {
final BrightcoveMediaController mediaController = new BrightcoveMediaController(brightcoveVideoView);
// Add "Ad Markers" where the Ads Manager says ads will appear.
mediaController.addListener(GoogleIMAEventType.ADS_MANAGER_LOADED, event -> {
AdsManager manager = (AdsManager) event.properties.get("adsManager");
if (manager != null) {
List<Float> cuepoints = manager.getAdCuePoints();
for (int i = 0; i < cuepoints.size(); i++) {
Float cuepoint = cuepoints.get(i);
BrightcoveSeekBar brightcoveSeekBar = mediaController.getBrightcoveSeekBar();
// If cuepoint is negative it means it is a POST ROLL.
int markerTime = cuepoint < 0 ? brightcoveSeekBar.getMax() : (int) (cuepoint * DateUtils.SECOND_IN_MILLIS);
mediaController.getBrightcoveSeekBar().addMarker(markerTime);
}
}
});
videoView.setMediaController(mediaController);
}
Aggregations