Search in sources :

Example 6 with AdsRequest

use of com.google.ads.interactivemedia.v3.api.AdsRequest in project zype-android by zype.

the class PlayerFragment method requestAds.

// 
// IMA SDK
// 
private void requestAds(String adTagUrl) {
    AdDisplayContainer adDisplayContainer = sdkFactory.createAdDisplayContainer();
    adDisplayContainer.setAdContainer(videoFrame);
    // Create the ads request.
    AdsRequest request = sdkFactory.createAdsRequest();
    request.setAdTagUrl(adTagUrl);
    request.setAdDisplayContainer(adDisplayContainer);
    request.setContentProgressProvider(new ContentProgressProvider() {

        @Override
        public VideoProgressUpdate getContentProgress() {
            if (isAdDisplayed || player == null || player.getDuration() <= 0) {
                return VideoProgressUpdate.VIDEO_TIME_NOT_READY;
            }
            return new VideoProgressUpdate(player.getCurrentPosition(), player.getDuration());
        }
    });
    // Request the ad. After the ad is loaded, onAdsManagerLoaded() will be called.
    adsLoader.requestAds(request);
}
Also used : AdsRequest(com.google.ads.interactivemedia.v3.api.AdsRequest) ContentProgressProvider(com.google.ads.interactivemedia.v3.api.player.ContentProgressProvider) AdDisplayContainer(com.google.ads.interactivemedia.v3.api.AdDisplayContainer) VideoProgressUpdate(com.google.ads.interactivemedia.v3.api.player.VideoProgressUpdate)

Example 7 with AdsRequest

use of com.google.ads.interactivemedia.v3.api.AdsRequest 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);
}
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 8 with AdsRequest

use of com.google.ads.interactivemedia.v3.api.AdsRequest 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)

Aggregations

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