Search in sources :

Example 1 with CompanionAdSlot

use of com.google.ads.interactivemedia.v3.api.CompanionAdSlot in project android-player-samples by BrightcoveOS.

the class MainActivity method setupGoogleIMA.

/**
     * Setup the Brightcove IMA Plugin: add some cue points; establish a factory object to
     * obtain the Google IMA SDK instance.
     */
private void setupGoogleIMA() {
    // Defer adding cue points until the set video event is triggered.
    eventEmitter.on(EventType.DID_SET_SOURCE, new EventListener() {

        @Override
        public void processEvent(Event event) {
            setupCuePoints((Source) event.properties.get(Event.SOURCE));
        }
    });
    // Establish the Google IMA SDK factory instance.
    final ImaSdkFactory sdkFactory = ImaSdkFactory.getInstance();
    // Enable logging of ad starts
    eventEmitter.on(EventType.AD_STARTED, new EventListener() {

        @Override
        public void processEvent(Event event) {
            Log.v(TAG, event.getType());
        }
    });
    // Enable logging of any failed attempts to play an ad.
    eventEmitter.on(GoogleIMAEventType.DID_FAIL_TO_PLAY_AD, new EventListener() {

        @Override
        public void processEvent(Event event) {
            Log.v(TAG, event.getType());
        }
    });
    // Enable logging of ad completions.
    eventEmitter.on(EventType.AD_COMPLETED, new EventListener() {

        @Override
        public void processEvent(Event event) {
            Log.v(TAG, event.getType());
        }
    });
    // Set up a listener for initializing AdsRequests. The Google IMA plugin emits an ad
    // request event in response to each cue point event.  The event processor (handler)
    // illustrates how to play ads back to back.
    eventEmitter.on(GoogleIMAEventType.ADS_REQUEST_FOR_VIDEO, new EventListener() {

        @Override
        public void processEvent(Event event) {
            // Create a container object for the ads to be presented.
            AdDisplayContainer container = sdkFactory.createAdDisplayContainer();
            container.setPlayer(googleIMAComponent.getVideoAdPlayer());
            container.setAdContainer(brightcoveVideoView);
            // Populate the container with the companion ad slots.
            ArrayList<CompanionAdSlot> companionAdSlots = new ArrayList<CompanionAdSlot>();
            CompanionAdSlot companionAdSlot = sdkFactory.createCompanionAdSlot();
            ViewGroup adFrame = (ViewGroup) findViewById(R.id.ad_frame);
            companionAdSlot.setContainer(adFrame);
            companionAdSlot.setSize(adFrame.getWidth(), adFrame.getHeight());
            companionAdSlots.add(companionAdSlot);
            container.setCompanionSlots(companionAdSlots);
            // Build the list of ads request objects, one per ad
            // URL, and point each to the ad display container
            // created above.
            ArrayList<AdsRequest> adsRequests = new ArrayList<AdsRequest>(googleAds.length);
            for (String adURL : googleAds) {
                AdsRequest adsRequest = sdkFactory.createAdsRequest();
                adsRequest.setAdTagUrl(adURL);
                adsRequest.setAdDisplayContainer(container);
                adsRequests.add(adsRequest);
            }
            // Respond to the event with the new ad requests.
            event.properties.put(GoogleIMAComponent.ADS_REQUESTS, adsRequests);
            eventEmitter.respond(event);
        }
    });
    // Create the Brightcove IMA Plugin and register the event emitter so that the plugin
    // can deal with video events.
    googleIMAComponent = new GoogleIMAComponent(brightcoveVideoView, eventEmitter);
}
Also used : ViewGroup(android.view.ViewGroup) GoogleIMAComponent(com.brightcove.ima.GoogleIMAComponent) ArrayList(java.util.ArrayList) CompanionAdSlot(com.google.ads.interactivemedia.v3.api.CompanionAdSlot) Source(com.brightcove.player.model.Source) AdsRequest(com.google.ads.interactivemedia.v3.api.AdsRequest) AdDisplayContainer(com.google.ads.interactivemedia.v3.api.AdDisplayContainer) Event(com.brightcove.player.event.Event) ImaSdkFactory(com.google.ads.interactivemedia.v3.api.ImaSdkFactory) EventListener(com.brightcove.player.event.EventListener)

Example 2 with CompanionAdSlot

use of com.google.ads.interactivemedia.v3.api.CompanionAdSlot in project android-player-samples by BrightcoveOS.

the class MainActivity method setupGoogleIMA.

/**
     * Setup the Brightcove IMA Plugin: add some cue points; establish a factory object to
     * obtain the Google IMA SDK instance.
     */
private void setupGoogleIMA() {
    // Defer adding cue points until the set video event is triggered.
    eventEmitter.on(EventType.DID_SET_SOURCE, new EventListener() {

        @Override
        public void processEvent(Event event) {
            setupCuePoints((Source) event.properties.get(Event.SOURCE));
        }
    });
    // Establish the Google IMA SDK factory instance.
    final ImaSdkFactory sdkFactory = ImaSdkFactory.getInstance();
    // Enable logging of ad starts.
    eventEmitter.on(EventType.AD_STARTED, new EventListener() {

        @Override
        public void processEvent(Event event) {
            Log.v(TAG, event.getType());
        }
    });
    // Enable logging of any failed attempts to play an ad.
    eventEmitter.on(GoogleIMAEventType.DID_FAIL_TO_PLAY_AD, new EventListener() {

        @Override
        public void processEvent(Event event) {
            Log.v(TAG, event.getType());
        }
    });
    // Enable logging of ad completions.
    eventEmitter.on(EventType.AD_COMPLETED, new EventListener() {

        @Override
        public void processEvent(Event event) {
            Log.v(TAG, event.getType());
        }
    });
    // Set up a listener for initializing AdsRequests. The Google IMA plugin emits an ad
    // request event in response to each cue point event.  The event processor (handler)
    // illustrates how to play ads back to back.
    eventEmitter.on(GoogleIMAEventType.ADS_REQUEST_FOR_VIDEO, new EventListener() {

        @Override
        public void processEvent(Event event) {
            // Create a container object for the ads to be presented.
            AdDisplayContainer container = sdkFactory.createAdDisplayContainer();
            container.setPlayer(googleIMAComponent.getVideoAdPlayer());
            container.setAdContainer(brightcoveVideoView);
            // Populate the container with the companion ad slots.
            ArrayList<CompanionAdSlot> companionAdSlots = new ArrayList<CompanionAdSlot>();
            CompanionAdSlot companionAdSlot = sdkFactory.createCompanionAdSlot();
            ViewGroup adFrame = (ViewGroup) findViewById(R.id.ad_frame);
            companionAdSlot.setContainer(adFrame);
            companionAdSlot.setSize(adFrame.getWidth(), adFrame.getHeight());
            companionAdSlots.add(companionAdSlot);
            container.setCompanionSlots(companionAdSlots);
            // Build the list of ad request objects, one per ad, and point each to the ad
            // display container created above.
            ArrayList<AdsRequest> adsRequests = new ArrayList<AdsRequest>(googleAds.length);
            for (String adURL : googleAds) {
                AdsRequest adsRequest = sdkFactory.createAdsRequest();
                adsRequest.setAdTagUrl(adURL);
                adsRequest.setAdDisplayContainer(container);
                adsRequests.add(adsRequest);
            }
            // Respond to the event with the new ad requests.
            event.properties.put(GoogleIMAComponent.ADS_REQUESTS, adsRequests);
            eventEmitter.respond(event);
        }
    });
    // Create the Brightcove IMA Plugin and register the event emitter so that the plugin
    // can deal with video events.
    googleIMAComponent = new GoogleIMAComponent(brightcoveVideoView, eventEmitter);
}
Also used : ViewGroup(android.view.ViewGroup) GoogleIMAComponent(com.brightcove.ima.GoogleIMAComponent) ArrayList(java.util.ArrayList) CompanionAdSlot(com.google.ads.interactivemedia.v3.api.CompanionAdSlot) Source(com.brightcove.player.model.Source) AdsRequest(com.google.ads.interactivemedia.v3.api.AdsRequest) AdDisplayContainer(com.google.ads.interactivemedia.v3.api.AdDisplayContainer) Event(com.brightcove.player.event.Event) ImaSdkFactory(com.google.ads.interactivemedia.v3.api.ImaSdkFactory) EventListener(com.brightcove.player.event.EventListener)

Aggregations

ViewGroup (android.view.ViewGroup)2 GoogleIMAComponent (com.brightcove.ima.GoogleIMAComponent)2 Event (com.brightcove.player.event.Event)2 EventListener (com.brightcove.player.event.EventListener)2 Source (com.brightcove.player.model.Source)2 AdDisplayContainer (com.google.ads.interactivemedia.v3.api.AdDisplayContainer)2 AdsRequest (com.google.ads.interactivemedia.v3.api.AdsRequest)2 CompanionAdSlot (com.google.ads.interactivemedia.v3.api.CompanionAdSlot)2 ImaSdkFactory (com.google.ads.interactivemedia.v3.api.ImaSdkFactory)2 ArrayList (java.util.ArrayList)2