use of com.google.ads.interactivemedia.v3.api.AdsLoader 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.AdsLoader in project ExoPlayer by google.
the class AdTagLoader method requestAds.
// Internal methods.
private AdsLoader requestAds(Context context, ImaSdkSettings imaSdkSettings, AdDisplayContainer adDisplayContainer) {
AdsLoader adsLoader = imaFactory.createAdsLoader(context, imaSdkSettings, adDisplayContainer);
adsLoader.addAdErrorListener(componentListener);
if (configuration.applicationAdErrorListener != null) {
adsLoader.addAdErrorListener(configuration.applicationAdErrorListener);
}
adsLoader.addAdsLoadedListener(componentListener);
AdsRequest request;
try {
request = ImaUtil.getAdsRequestForAdTagDataSpec(imaFactory, adTagDataSpec);
} catch (IOException e) {
adPlaybackState = new AdPlaybackState(adsId);
updateAdPlaybackState();
pendingAdLoadError = AdLoadException.createForAllAds(e);
maybeNotifyPendingAdLoadError();
return adsLoader;
}
pendingAdRequestContext = new Object();
request.setUserRequestContext(pendingAdRequestContext);
if (configuration.enableContinuousPlayback != null) {
request.setContinuousPlayback(configuration.enableContinuousPlayback);
}
if (configuration.vastLoadTimeoutMs != TIMEOUT_UNSET) {
request.setVastLoadTimeout(configuration.vastLoadTimeoutMs);
}
request.setContentProgressProvider(componentListener);
adsLoader.requestAds(request);
return adsLoader;
}
Aggregations