Search in sources :

Example 1 with EventListener

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

the class MainActivityTest method testPlay.

/**
     * Test for pre, mid, and post rolls.
     */
public void testPlay() throws InterruptedException {
    final CountDownLatch latch = new CountDownLatch(2);
    Log.v(TAG, "testPlay");
    eventEmitter.on(EventType.AD_STARTED, new EventListener() {

        @Override
        public void processEvent(Event event) {
            assertTrue("Should not have started an ad: " + state, state != State.STARTED_AD);
            switch(state) {
                case STARTING_CONTENT:
                    numPrerollsPlayed++;
                    break;
                case STARTED_CONTENT:
                    numMidrollsPlayed++;
                    break;
                case COMPLETED_CONTENT:
                    numPostrollsPlayed++;
                    break;
                default:
                    Log.e(TAG, "Unexpected state: " + state);
            }
            state = State.STARTED_AD;
        }
    });
    eventEmitter.on(EventType.AD_COMPLETED, new EventListener() {

        @Override
        public void processEvent(Event event) {
            assertTrue("Should have started an ad: " + state, state == State.STARTED_AD);
            state = State.COMPLETED_AD;
        }
    });
    eventEmitter.on(EventType.WILL_CHANGE_VIDEO, new EventListener() {

        @Override
        public void processEvent(Event event) {
            state = State.STARTING_CONTENT;
            if (eventEmitter != null) {
                eventEmitter.once(EventType.PROGRESS, new EventListener() {

                    @Override
                    public void processEvent(Event event) {
                        assertTrue("Should have played a preroll: " + state, state == State.COMPLETED_AD);
                        state = State.STARTED_CONTENT;
                    }
                });
            }
        }
    });
    eventEmitter.on(EventType.COMPLETED, new EventListener() {

        @Override
        public void processEvent(Event event) {
            if (event.properties.containsKey(Event.SKIP_CUE_POINTS)) {
                latch.countDown();
            } else {
                state = State.COMPLETED_CONTENT;
            }
        }
    });
    assertTrue("Timeout occurred.", latch.await(3, TimeUnit.MINUTES));
    brightcoveVideoView.stopPlayback();
    assertEquals("Should have played 2 prerolls.", 2, numPrerollsPlayed);
    assertEquals("Should have played 2 midrolls.", 2, numMidrollsPlayed);
    assertEquals("Should have played 2 postrolls.", 2, numPostrollsPlayed);
}
Also used : Event(com.brightcove.player.event.Event) EventListener(com.brightcove.player.event.EventListener) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 2 with EventListener

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

the class GoogleCastComponentTest method testCastMediaToRemoteDeviceAndBackFromPaused.

/**
     * Test the successful local to remote playback and then remote to local
     * with the media starting in the PAUSE state on the local device.
     *
     * @throws InterruptedException
     */
public void testCastMediaToRemoteDeviceAndBackFromPaused() throws InterruptedException {
    Log.v(TAG, "testCastMediaToRemoteDeviceAndBackFromPaused");
    final CountDownLatch countDownLatch = new CountDownLatch(2);
    brightcoveVideoView.pause();
    solo.sleep(3000);
    eventEmitter.once(EventType.DID_STOP, new EventListener() {

        @Override
        public void processEvent(Event event) {
            assertFalse("BrightVideoVideo is not playing.", brightcoveVideoView.isPlaying());
            countDownLatch.countDown();
        }
    });
    solo.clickOnActionBarItem(R.id.media_router_menu_item);
    solo.clickInList(0);
    solo.sleep(6000);
    brightcoveVideoView.start();
    assertFalse("BrightcoveVideoView playback did not start.", brightcoveVideoView.isPlaying());
    solo.waitForActivity(VideoCastControllerActivity.class);
    solo.sleep(10000);
    solo.assertCurrentActivity("VideoCastControllerActivity is displayed", VideoCastControllerActivity.class);
    List<View> views = solo.getCurrentViews();
    for (View v : views) {
        if (v instanceof android.support.v7.app.MediaRouteButton) {
            solo.clickOnView(v);
        }
    }
    solo.sleep(3000);
    solo.clickOnButton("Disconnect");
    solo.sleep(3000);
    countDownLatch.countDown();
    assertTrue("Timeout occurred.", countDownLatch.await(3, TimeUnit.MINUTES));
}
Also used : Event(com.brightcove.player.event.Event) EventListener(com.brightcove.player.event.EventListener) CountDownLatch(java.util.concurrent.CountDownLatch) BrightcoveVideoView(com.brightcove.player.view.BrightcoveVideoView) View(android.view.View)

Example 3 with EventListener

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

the class GoogleCastComponentTest method testCastMediaToRemoteDeviceAndBackFromPlaying.

/**
     * Test the successful local to remote playback and then remote to local
     * with the media starting in the PLAY state on the local device.
     * @throws InterruptedException
     */
public void testCastMediaToRemoteDeviceAndBackFromPlaying() throws InterruptedException {
    Log.v(TAG, "testCastMediaToRemoteDeviceAndBackFromPlaying");
    final CountDownLatch countDownLatch = new CountDownLatch(2);
    solo.clickOnActionBarItem(R.id.media_router_menu_item);
    solo.clickInList(0);
    eventEmitter.once(EventType.DID_PAUSE, new EventListener() {

        @Override
        public void processEvent(Event event) {
            assertFalse("BrightVideoVideo is paused.", brightcoveVideoView.isPlaying());
            countDownLatch.countDown();
        }
    });
    solo.waitForActivity(VideoCastControllerActivity.class);
    solo.sleep(10000);
    solo.assertCurrentActivity("VideoCastControllerActivity is displayed", VideoCastControllerActivity.class);
    List<View> views = solo.getCurrentViews();
    for (View v : views) {
        if (v instanceof android.support.v7.app.MediaRouteButton) {
            solo.clickOnView(v);
        }
    }
    solo.sleep(3000);
    solo.clickOnButton("Disconnect");
    solo.sleep(3000);
    countDownLatch.countDown();
    assertTrue("Timeout occurred.", countDownLatch.await(3, TimeUnit.MINUTES));
}
Also used : Event(com.brightcove.player.event.Event) EventListener(com.brightcove.player.event.EventListener) CountDownLatch(java.util.concurrent.CountDownLatch) BrightcoveVideoView(com.brightcove.player.view.BrightcoveVideoView) View(android.view.View)

Example 4 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);
// 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 5 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);
// 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

Event (com.brightcove.player.event.Event)20 EventListener (com.brightcove.player.event.EventListener)20 Video (com.brightcove.player.model.Video)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 ViewGroup (android.view.ViewGroup)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 FreeWheelController (com.brightcove.freewheel.controller.FreeWheelController)4 GoogleIMAComponent (com.brightcove.ima.GoogleIMAComponent)4 AdDisplayContainer (com.google.ads.interactivemedia.v3.api.AdDisplayContainer)4 AdsRequest (com.google.ads.interactivemedia.v3.api.AdsRequest)4 ImaSdkFactory (com.google.ads.interactivemedia.v3.api.ImaSdkFactory)4 IAdContext (tv.freewheel.ad.interfaces.IAdContext)4 IConstants (tv.freewheel.ad.interfaces.IConstants)4 ISlot (tv.freewheel.ad.interfaces.ISlot)4 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 Instrumentation (android.app.Instrumentation)2