use of com.google.ads.interactivemedia.v3.api.AdsManager in project ExoPlayer by google.
the class AdTagLoader method handleAdPrepareError.
private void handleAdPrepareError(int adGroupIndex, int adIndexInAdGroup, Exception exception) {
if (configuration.debugModeEnabled) {
Log.d(TAG, "Prepare error for ad " + adIndexInAdGroup + " in group " + adGroupIndex, exception);
}
if (adsManager == null) {
Log.w(TAG, "Ignoring ad prepare error after release");
return;
}
if (imaAdState == IMA_AD_STATE_NONE) {
// Send IMA a content position at the ad group so that it will try to play it, at which point
// we can notify that it failed to load.
fakeContentProgressElapsedRealtimeMs = SystemClock.elapsedRealtime();
fakeContentProgressOffsetMs = Util.usToMs(adPlaybackState.getAdGroup(adGroupIndex).timeUs);
if (fakeContentProgressOffsetMs == C.TIME_END_OF_SOURCE) {
fakeContentProgressOffsetMs = contentDurationMs;
}
pendingAdPrepareErrorAdInfo = new AdInfo(adGroupIndex, adIndexInAdGroup);
} else {
AdMediaInfo adMediaInfo = checkNotNull(imaAdMediaInfo);
// We're already playing an ad.
if (adIndexInAdGroup > playingAdIndexInAdGroup) {
// which means that the ad after will load (if any).
for (int i = 0; i < adCallbacks.size(); i++) {
adCallbacks.get(i).onEnded(adMediaInfo);
}
}
playingAdIndexInAdGroup = adPlaybackState.getAdGroup(adGroupIndex).getFirstAdIndexToPlay();
for (int i = 0; i < adCallbacks.size(); i++) {
adCallbacks.get(i).onError(checkNotNull(adMediaInfo));
}
}
adPlaybackState = adPlaybackState.withAdLoadError(adGroupIndex, adIndexInAdGroup);
updateAdPlaybackState();
}
use of com.google.ads.interactivemedia.v3.api.AdsManager in project ExoPlayer by google.
the class AdTagLoader method activate.
/**
* Activates playback.
*/
public void activate(Player player) {
this.player = player;
player.addListener(this);
boolean playWhenReady = player.getPlayWhenReady();
onTimelineChanged(player.getCurrentTimeline(), Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE);
@Nullable AdsManager adsManager = this.adsManager;
if (!AdPlaybackState.NONE.equals(adPlaybackState) && adsManager != null && imaPausedContent) {
// Check whether the current ad break matches the expected ad break based on the current
// position. If not, discard the current ad break so that the correct ad break can load.
long contentPositionMs = getContentPeriodPositionMs(player, timeline, period);
int adGroupForPositionIndex = adPlaybackState.getAdGroupIndexForPositionUs(Util.msToUs(contentPositionMs), Util.msToUs(contentDurationMs));
if (adGroupForPositionIndex != C.INDEX_UNSET && imaAdInfo != null && imaAdInfo.adGroupIndex != adGroupForPositionIndex) {
if (configuration.debugModeEnabled) {
Log.d(TAG, "Discarding preloaded ad " + imaAdInfo);
}
adsManager.discardAdBreak();
}
if (playWhenReady) {
adsManager.resume();
}
}
}
use of com.google.ads.interactivemedia.v3.api.AdsManager in project ExoPlayer by google.
the class AdTagLoader method onPlaybackStateChanged.
@Override
public void onPlaybackStateChanged(@Player.State int playbackState) {
@Nullable Player player = this.player;
if (adsManager == null || player == null) {
return;
}
if (playbackState == Player.STATE_BUFFERING && !player.isPlayingAd() && isWaitingForAdToLoad()) {
waitingForPreloadElapsedRealtimeMs = SystemClock.elapsedRealtime();
} else if (playbackState == Player.STATE_READY) {
waitingForPreloadElapsedRealtimeMs = C.TIME_UNSET;
}
handlePlayerStateChanged(player.getPlayWhenReady(), playbackState);
}
use of com.google.ads.interactivemedia.v3.api.AdsManager in project zype-android by zype.
the class PlayerFragment method onActivityCreated.
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
//
// IMA SDK
//
// Create an AdsLoader.
sdkFactory = ImaSdkFactory.getInstance();
adsLoader = sdkFactory.createAdsLoader(this.getActivity());
// Add listeners for when ads are loaded and for errors.
adsLoader.addAdErrorListener(this);
adsLoader.addAdsLoadedListener(new AdsLoader.AdsLoadedListener() {
@Override
public void onAdsManagerLoaded(AdsManagerLoadedEvent adsManagerLoadedEvent) {
// Ads were successfully loaded, so get the AdsManager instance. AdsManager has
// events for ad playback and errors.
adsManager = adsManagerLoadedEvent.getAdsManager();
// Attach event and error event listeners.
adsManager.addAdErrorListener(PlayerFragment.this);
adsManager.addAdEventListener(PlayerFragment.this);
adsManager.init();
}
});
sensorViewModel = ViewModelProviders.of(getActivity()).get(SensorViewModel.class);
videoDetailViewModel = ViewModelProviders.of(getActivity()).get(VideoDetailViewModel.class);
if (playerViewModel.isTrailer().getValue()) {
ImageButton buttonCloseTrailer = getView().findViewById(R.id.buttonCloseTrailer);
buttonCloseTrailer.setVisibility(View.VISIBLE);
buttonCloseTrailer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
stop();
videoDetailViewModel.onVideoFinished(true);
playerViewModel.setTrailerVideoId(null);
}
});
}
setHasOptionsMenu(true);
}
use of com.google.ads.interactivemedia.v3.api.AdsManager in project android-player-samples by BrightcoveOS.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
// When extending the BrightcovePlayer, we must assign the BrightcoveExoPlayerVideoView before
// entering the superclass. This allows for some stock video player lifecycle
// management.
setContentView(R.layout.ima_activity_main);
brightcoveVideoView = (BrightcoveExoPlayerVideoView) findViewById(R.id.brightcove_video_view);
final BrightcoveMediaController mediaController = new BrightcoveMediaController(brightcoveVideoView);
// Add "Ad Markers" where the Ads Manager says ads will appear.
mediaController.addListener(GoogleIMAEventType.ADS_MANAGER_LOADED, new EventListener() {
@Override
public void processEvent(Event event) {
AdsManager manager = (AdsManager) event.properties.get("adsManager");
List<Float> cuepoints = manager.getAdCuePoints();
for (int i = 0; i < cuepoints.size(); i++) {
Float cuepoint = cuepoints.get(i);
mediaController.getBrightcoveSeekBar().addMarker((int) (cuepoint * DateUtils.SECOND_IN_MILLIS));
}
}
});
brightcoveVideoView.setMediaController(mediaController);
super.onCreate(savedInstanceState);
eventEmitter = brightcoveVideoView.getEventEmitter();
// Use a procedural abstraction to setup the Google IMA SDK via the plugin.
setupGoogleIMA();
Map<String, String> options = new HashMap<String, String>();
List<String> values = new ArrayList<String>(Arrays.asList(VideoFields.DEFAULT_FIELDS));
values.remove(VideoFields.HLS_URL);
options.put("video_fields", StringUtil.join(values, ","));
Catalog catalog = new Catalog("ErQk9zUeDVLIp8Dc7aiHKq8hDMgkv5BFU7WGshTc-hpziB3BuYh28A..");
catalog.findVideoByReferenceID("shark", new VideoListener() {
public void onVideo(Video video) {
brightcoveVideoView.add(video);
// Auto play: the GoogleIMAComponent will postpone
// playback until the Ad Rules are loaded.
brightcoveVideoView.start();
}
public void onError(String error) {
Log.e(TAG, error);
}
});
}
Aggregations