Search in sources :

Example 1 with ImaSdkFactory

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

the class MainActivity method setupGoogleIMA.

/**
     * Setup the Brightcove IMA Plugin.
     */
private void setupGoogleIMA() {
    // Establish the Google IMA SDK factory instance.
    final ImaSdkFactory sdkFactory = ImaSdkFactory.getInstance();
    // Enable logging up ad start.
    eventEmitter.on(EventType.AD_STARTED, new EventListener() {

        @Override
        public void processEvent(Event event) {
            Log.v(TAG, event.getType());
        }
    });
    // Enable logging 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 upon ad completion.
    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 as a result of
    // initializeAdsRequests() being called.
    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);
            // Build an ads request object and point it to the ad
            // display container created above.
            AdsRequest adsRequest = sdkFactory.createAdsRequest();
            adsRequest.setAdTagUrl(adRulesURL);
            adsRequest.setAdDisplayContainer(container);
            ArrayList<AdsRequest> adsRequests = new ArrayList<AdsRequest>(1);
            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 pass in the event
    // emitter so that the plugin can integrate with the SDK.
    googleIMAComponent = new GoogleIMAComponent(brightcoveVideoView, eventEmitter, true);
// Calling GoogleIMAComponent.initializeAdsRequests() is no longer necessary.
}
Also used : AdsRequest(com.google.ads.interactivemedia.v3.api.AdsRequest) GoogleIMAComponent(com.brightcove.ima.GoogleIMAComponent) AdDisplayContainer(com.google.ads.interactivemedia.v3.api.AdDisplayContainer) ArrayList(java.util.ArrayList) ImaSdkFactory(com.google.ads.interactivemedia.v3.api.ImaSdkFactory) Event(com.brightcove.player.event.Event) EventListener(com.brightcove.player.event.EventListener)

Example 2 with ImaSdkFactory

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

the class MainActivity method setupGoogleIMA.

/**
     * Setup the Brightcove IMA Plugin.
     */
private void setupGoogleIMA() {
    // Establish the Google IMA SDK factory instance.
    final ImaSdkFactory sdkFactory = ImaSdkFactory.getInstance();
    // Enable logging up ad start.
    eventEmitter.on(EventType.AD_STARTED, new EventListener() {

        @Override
        public void processEvent(Event event) {
            Log.v(TAG, event.getType());
        }
    });
    // Enable logging 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 upon ad completion.
    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 as a result of
    // initializeAdsRequests() being called.
    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);
            // Build an ads request object and point it to the ad
            // display container created above.
            AdsRequest adsRequest = sdkFactory.createAdsRequest();
            adsRequest.setAdTagUrl(adRulesURL);
            adsRequest.setAdDisplayContainer(container);
            ArrayList<AdsRequest> adsRequests = new ArrayList<AdsRequest>(1);
            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 pass in the event
    // emitter so that the plugin can integrate with the SDK.
    googleIMAComponent = new GoogleIMAComponent(brightcoveVideoView, eventEmitter, true);
// Calling GoogleIMAComponent.initializeAdsRequests() is no longer necessary.
}
Also used : AdsRequest(com.google.ads.interactivemedia.v3.api.AdsRequest) GoogleIMAComponent(com.brightcove.ima.GoogleIMAComponent) AdDisplayContainer(com.google.ads.interactivemedia.v3.api.AdDisplayContainer) ArrayList(java.util.ArrayList) ImaSdkFactory(com.google.ads.interactivemedia.v3.api.ImaSdkFactory) Event(com.brightcove.player.event.Event) EventListener(com.brightcove.player.event.EventListener)

Example 3 with ImaSdkFactory

use of com.google.ads.interactivemedia.v3.api.ImaSdkFactory in project ExoPlayer by google.

the class ImaServerSideAdInsertionMediaSource method createStreamDisplayContainer.

private static StreamDisplayContainer createStreamDisplayContainer(ImaSdkFactory imaSdkFactory, ImaUtil.ServerSideAdInsertionConfiguration config, StreamPlayer streamPlayer) {
    StreamDisplayContainer container = ImaSdkFactory.createStreamDisplayContainer(checkNotNull(config.adViewProvider.getAdViewGroup()), streamPlayer);
    container.setCompanionSlots(config.companionAdSlots);
    registerFriendlyObstructions(imaSdkFactory, container, config.adViewProvider);
    return container;
}
Also used : StreamDisplayContainer(com.google.ads.interactivemedia.v3.api.StreamDisplayContainer)

Example 4 with ImaSdkFactory

use of com.google.ads.interactivemedia.v3.api.ImaSdkFactory in project ExoPlayer by google.

the class ImaServerSideAdInsertionMediaSource method registerFriendlyObstructions.

private static void registerFriendlyObstructions(ImaSdkFactory imaSdkFactory, StreamDisplayContainer container, AdViewProvider adViewProvider) {
    for (int i = 0; i < adViewProvider.getAdOverlayInfos().size(); i++) {
        AdOverlayInfo overlayInfo = adViewProvider.getAdOverlayInfos().get(i);
        container.registerFriendlyObstruction(imaSdkFactory.createFriendlyObstruction(overlayInfo.view, ImaUtil.getFriendlyObstructionPurpose(overlayInfo.purpose), overlayInfo.reasonDetail != null ? overlayInfo.reasonDetail : "Unknown reason"));
    }
}
Also used : AdOverlayInfo(com.google.android.exoplayer2.ui.AdOverlayInfo) CuePoint(com.google.ads.interactivemedia.v3.api.CuePoint)

Example 5 with ImaSdkFactory

use of com.google.ads.interactivemedia.v3.api.ImaSdkFactory 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, event -> {
        Source source = event.getProperty(Event.SOURCE, Source.class);
        if (source != null) {
            setupCuePoints(source);
        }
    });
    // Establish the Google IMA SDK factory instance.
    final ImaSdkFactory sdkFactory = ImaSdkFactory.getInstance();
    // Enable logging of ad starts
    eventEmitter.on(EventType.AD_STARTED, event -> Log.v(TAG, event.getType()));
    // Enable logging of any failed attempts to play an ad.
    eventEmitter.on(GoogleIMAEventType.DID_FAIL_TO_PLAY_AD, event -> Log.v(TAG, event.getType()));
    // Enable logging of ad completions.
    eventEmitter.on(EventType.AD_COMPLETED, 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, event -> {
        // Create a container object for the ads to be presented.
        AdDisplayContainer container = googleIMAComponent.getAdDisplayContainer();
        if (container != null && !brightcoveVideoView.getBrightcoveMediaController().isTvMode) {
            // Populate the container with the companion ad slots.
            ArrayList<CompanionAdSlot> companionAdSlots = new ArrayList<>();
            CompanionAdSlot companionAdSlot = sdkFactory.createCompanionAdSlot();
            ViewGroup adFrame = findViewById(R.id.ad_frame);
            companionAdSlot.setContainer(adFrame);
            companionAdSlot.setSize(COMPANION_SLOT_WIDTH, COMPANION_SLOT_HEIGHT);
            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<>(googleAds.length);
        for (String adURL : googleAds) {
            AdsRequest adsRequest = sdkFactory.createAdsRequest();
            adsRequest.setAdTagUrl(adURL);
            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.Builder(brightcoveVideoView, eventEmitter).build();
}
Also used : AdsRequest(com.google.ads.interactivemedia.v3.api.AdsRequest) ViewGroup(android.view.ViewGroup) AdDisplayContainer(com.google.ads.interactivemedia.v3.api.AdDisplayContainer) ArrayList(java.util.ArrayList) ImaSdkFactory(com.google.ads.interactivemedia.v3.api.ImaSdkFactory) CompanionAdSlot(com.google.ads.interactivemedia.v3.api.CompanionAdSlot) Source(com.brightcove.player.model.Source)

Aggregations

AdsRequest (com.google.ads.interactivemedia.v3.api.AdsRequest)7 ImaSdkFactory (com.google.ads.interactivemedia.v3.api.ImaSdkFactory)7 ArrayList (java.util.ArrayList)7 GoogleIMAComponent (com.brightcove.ima.GoogleIMAComponent)6 AdDisplayContainer (com.google.ads.interactivemedia.v3.api.AdDisplayContainer)5 Event (com.brightcove.player.event.Event)4 EventListener (com.brightcove.player.event.EventListener)4 ViewGroup (android.view.ViewGroup)2 Source (com.brightcove.player.model.Source)2 CompanionAdSlot (com.google.ads.interactivemedia.v3.api.CompanionAdSlot)2 CuePoint (com.google.ads.interactivemedia.v3.api.CuePoint)1 StreamDisplayContainer (com.google.ads.interactivemedia.v3.api.StreamDisplayContainer)1 AdOverlayInfo (com.google.android.exoplayer2.ui.AdOverlayInfo)1