Search in sources :

Example 1 with AdsLoader

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);
}
Also used : ImageButton(android.widget.ImageButton) AdsManagerLoadedEvent(com.google.ads.interactivemedia.v3.api.AdsManagerLoadedEvent) VideoDetailViewModel(com.zype.android.ui.video_details.VideoDetailViewModel) ImageView(android.widget.ImageView) SurfaceView(android.view.SurfaceView) View(android.view.View) AdsLoader(com.google.ads.interactivemedia.v3.api.AdsLoader)

Example 2 with AdsLoader

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;
}
Also used : AdsRequest(com.google.ads.interactivemedia.v3.api.AdsRequest) AdPlaybackState(com.google.android.exoplayer2.source.ads.AdPlaybackState) IOException(java.io.IOException) AdsLoader(com.google.ads.interactivemedia.v3.api.AdsLoader)

Aggregations

AdsLoader (com.google.ads.interactivemedia.v3.api.AdsLoader)2 SurfaceView (android.view.SurfaceView)1 View (android.view.View)1 ImageButton (android.widget.ImageButton)1 ImageView (android.widget.ImageView)1 AdsManagerLoadedEvent (com.google.ads.interactivemedia.v3.api.AdsManagerLoadedEvent)1 AdsRequest (com.google.ads.interactivemedia.v3.api.AdsRequest)1 AdPlaybackState (com.google.android.exoplayer2.source.ads.AdPlaybackState)1 VideoDetailViewModel (com.zype.android.ui.video_details.VideoDetailViewModel)1 IOException (java.io.IOException)1