Search in sources :

Example 16 with EventListener

use of com.brightcove.player.event.EventListener 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)

Example 17 with EventListener

use of com.brightcove.player.event.EventListener in project android-player-samples by BrightcoveOS.

the class GoogleCastComponentTest method setUp.

/**
     * Initialize Robotium, the BrightcoveVideoView and the EventEmitter.
     * Start media playback.
     * @throws Exception
     */
@Override
protected void setUp() throws Exception {
    super.setUp();
    setActivityInitialTouchMode(true);
    castActivity = getActivity();
    solo = new Solo(getInstrumentation(), castActivity);
    brightcoveVideoView = (BrightcoveVideoView) castActivity.findViewById(R.id.brightcove_video_view);
    eventEmitter = brightcoveVideoView.getEventEmitter();
    final CountDownLatch countDownLatch = new CountDownLatch(2);
    eventEmitter.once(EventType.DID_SET_VIDEO, new EventListener() {

        @Override
        public void processEvent(Event event) {
            brightcoveVideoView.start();
            countDownLatch.countDown();
        }
    });
    eventEmitter.once(EventType.DID_PLAY, new EventListener() {

        @Override
        public void processEvent(Event event) {
            assertTrue("BrightcoveVideoView is playing.", brightcoveVideoView.isPlaying());
            countDownLatch.countDown();
        }
    });
    assertTrue("Timeout occurred.", countDownLatch.await(1, TimeUnit.MINUTES));
}
Also used : Solo(com.robotium.solo.Solo) Event(com.brightcove.player.event.Event) EventListener(com.brightcove.player.event.EventListener) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 18 with EventListener

use of com.brightcove.player.event.EventListener in project android-player-samples by BrightcoveOS.

the class MainActivity method initMediaController.

public void initMediaController(final BaseVideoView brightcoveVideoView) {
    if (BrightcoveMediaController.checkTvMode(this)) {
        // Use this method to verify if we're running in Android TV
        brightcoveVideoView.setMediaController(new BrightcoveMediaController(brightcoveVideoView, R.layout.my_tv_media_controller));
    } else {
        brightcoveVideoView.setMediaController(new BrightcoveMediaController(brightcoveVideoView, R.layout.my_media_controller));
    }
    initButtons(brightcoveVideoView);
    // This event is sent by the BrightcovePlayer Activity when the onConfigurationChanged has been called.
    brightcoveVideoView.getEventEmitter().on(EventType.CONFIGURATION_CHANGED, new EventListener() {

        @Override
        public void processEvent(Event event) {
            initButtons(brightcoveVideoView);
        }
    });
}
Also used : Event(com.brightcove.player.event.Event) EventListener(com.brightcove.player.event.EventListener) BrightcoveMediaController(com.brightcove.player.mediacontroller.BrightcoveMediaController)

Example 19 with EventListener

use of com.brightcove.player.event.EventListener in project android-player-samples by BrightcoveOS.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    // When extending the BrightcovePlayer, we must assign the BrightcoveExoPlayerVideoView before
    // entering the superclass. This allows for some stock video player lifecycle
    // management.
    setContentView(R.layout.ima_activity_main);
    brightcoveVideoView = (BrightcoveExoPlayerVideoView) findViewById(R.id.brightcove_video_view);
    final BrightcoveMediaController mediaController = new BrightcoveMediaController(brightcoveVideoView);
    // Add "Ad Markers" where the Ads Manager says ads will appear.
    mediaController.addListener(GoogleIMAEventType.ADS_MANAGER_LOADED, new EventListener() {

        @Override
        public void processEvent(Event event) {
            AdsManager manager = (AdsManager) event.properties.get("adsManager");
            List<Float> cuepoints = manager.getAdCuePoints();
            for (int i = 0; i < cuepoints.size(); i++) {
                Float cuepoint = cuepoints.get(i);
                mediaController.getBrightcoveSeekBar().addMarker((int) (cuepoint * DateUtils.SECOND_IN_MILLIS));
            }
        }
    });
    brightcoveVideoView.setMediaController(mediaController);
    super.onCreate(savedInstanceState);
    eventEmitter = brightcoveVideoView.getEventEmitter();
    // Use a procedural abstraction to setup the Google IMA SDK via the plugin.
    setupGoogleIMA();
    Map<String, String> options = new HashMap<String, String>();
    List<String> values = new ArrayList<String>(Arrays.asList(VideoFields.DEFAULT_FIELDS));
    values.remove(VideoFields.HLS_URL);
    options.put("video_fields", StringUtil.join(values, ","));
    Catalog catalog = new Catalog("ErQk9zUeDVLIp8Dc7aiHKq8hDMgkv5BFU7WGshTc-hpziB3BuYh28A..");
    catalog.findVideoByReferenceID("shark", new VideoListener() {

        public void onVideo(Video video) {
            brightcoveVideoView.add(video);
            // Auto play: the GoogleIMAComponent will postpone
            // playback until the Ad Rules are loaded.
            brightcoveVideoView.start();
        }

        public void onError(String error) {
            Log.e(TAG, error);
        }
    });
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Catalog(com.brightcove.player.media.Catalog) BrightcoveMediaController(com.brightcove.player.mediacontroller.BrightcoveMediaController) AdsManager(com.google.ads.interactivemedia.v3.api.AdsManager) Video(com.brightcove.player.model.Video) Event(com.brightcove.player.event.Event) ArrayList(java.util.ArrayList) List(java.util.List) EventListener(com.brightcove.player.event.EventListener) VideoListener(com.brightcove.player.media.VideoListener)

Example 20 with EventListener

use of com.brightcove.player.event.EventListener 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)

Aggregations

Event (com.brightcove.player.event.Event)24 EventListener (com.brightcove.player.event.EventListener)24 ArrayList (java.util.ArrayList)9 GoogleIMAComponent (com.brightcove.ima.GoogleIMAComponent)7 AdDisplayContainer (com.google.ads.interactivemedia.v3.api.AdDisplayContainer)7 AdsRequest (com.google.ads.interactivemedia.v3.api.AdsRequest)7 ImaSdkFactory (com.google.ads.interactivemedia.v3.api.ImaSdkFactory)7 ViewGroup (android.view.ViewGroup)6 Video (com.brightcove.player.model.Video)6 List (java.util.List)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 FreeWheelController (com.brightcove.freewheel.controller.FreeWheelController)4 IAdContext (tv.freewheel.ad.interfaces.IAdContext)4 IConstants (tv.freewheel.ad.interfaces.IConstants)4 ISlot (tv.freewheel.ad.interfaces.ISlot)4 BrightcoveMediaController (com.brightcove.player.mediacontroller.BrightcoveMediaController)3 AdRequestConfiguration (tv.freewheel.ad.request.config.AdRequestConfiguration)3 NonTemporalSlotConfiguration (tv.freewheel.ad.request.config.NonTemporalSlotConfiguration)3 TemporalSlotConfiguration (tv.freewheel.ad.request.config.TemporalSlotConfiguration)3 VideoAssetConfiguration (tv.freewheel.ad.request.config.VideoAssetConfiguration)3