Search in sources :

Example 16 with Event

use of com.brightcove.player.event.Event 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 17 with Event

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

the class MainActivity method registerEventHandlers.

// Private instance methods
/**
 * Procedural abstraction used to setup event handlers for the OnceUX plugin.
 */
private void registerEventHandlers() {
    // Handle the case where the ad data URL has not been supplied to the plugin.
    EventEmitter eventEmitter = brightcoveVideoView.getEventEmitter();
    eventEmitter.on(OnceUxEventType.NO_AD_DATA_URL, new EventListener() {

        @Override
        public void processEvent(Event event) {
            // Log the event and display a warning message (later)
            Log.e(TAG, event.getType());
        // TODO: throw up a stock Android warning widget.
        }
    });
}
Also used : EventEmitter(com.brightcove.player.event.EventEmitter) Event(com.brightcove.player.event.Event) EventListener(com.brightcove.player.event.EventListener)

Example 18 with Event

use of com.brightcove.player.event.Event 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 19 with Event

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

the class MainActivity method setupFreeWheel.

private void setupFreeWheel() {
    // change this to new FrameLayout based constructor.
    FreeWheelController freeWheelController = new FreeWheelController(this, brightcoveVideoView, eventEmitter);
    // configure your own IAdManager or supply connection information
    freeWheelController.setAdURL("http://demo.v.fwmrm.net/");
    freeWheelController.setAdNetworkId(90750);
    freeWheelController.setProfile("3pqa_android");
    /*
         * Choose one of these to determine the ad policy (basically server or client).
         * - 3pqa_section - uses FW server rules - always returns a preroll and a postroll.  It should return whatever midroll slots you request though.
         * - 3pqa_section_nocbp - returns the slots that you request.
         */
    // freeWheelController.setSiteSectionId("3pqa_section");
    freeWheelController.setSiteSectionId("3pqa_section_nocbp");
    eventEmitter.on(FreeWheelEventType.SHOW_DISPLAY_ADS, new EventListener() {

        @Override
        public void processEvent(Event event) {
            @SuppressWarnings("unchecked") List<ISlot> slots = (List<ISlot>) event.properties.get(FreeWheelController.AD_SLOTS_KEY);
            ViewGroup adView = findViewById(R.id.ad_frame);
            // Clean out any previous display ads
            for (int i = 0; i < adView.getChildCount(); i++) {
                adView.removeViewAt(i);
            }
            for (ISlot slot : slots) {
                adView.addView(slot.getBase());
                slot.play();
            }
        }
    });
    eventEmitter.on(FreeWheelEventType.WILL_SUBMIT_AD_REQUEST, new EventListener() {

        @Override
        public void processEvent(Event event) {
            Video video = (Video) event.properties.get(Event.VIDEO);
            IAdContext adContext = (IAdContext) event.properties.get(FreeWheelController.AD_CONTEXT_KEY);
            IConstants adConstants = adContext.getConstants();
            AdRequestConfiguration adRequestConfiguration = (AdRequestConfiguration) event.properties.get(FreeWheelController.AD_REQUEST_CONFIGURATION_KEY);
            // This overrides what the plugin does by default for setVideoAsset() which is to pass in currentVideo.getId().
            VideoAssetConfiguration fwVideoAssetConfiguration = new VideoAssetConfiguration("3pqa_video", IConstants.IdType.CUSTOM, // FW uses their duration as seconds; Android is in milliseconds
            video.getDuration() / 1000, IConstants.VideoAssetDurationType.EXACT, IConstants.VideoAssetAutoPlayType.ATTENDED);
            adRequestConfiguration.setVideoAssetConfiguration(fwVideoAssetConfiguration);
            NonTemporalSlotConfiguration companionSlot = new NonTemporalSlotConfiguration("300x250slot", null, 300, 250);
            companionSlot.setCompanionAcceptance(true);
            adRequestConfiguration.addSlotConfiguration(companionSlot);
            // Add preroll
            Log.v(TAG, "Adding temporal slot for prerolls");
            TemporalSlotConfiguration prerollSlot = new TemporalSlotConfiguration("larry", adConstants.ADUNIT_PREROLL(), 0);
            adRequestConfiguration.addSlotConfiguration(prerollSlot);
            // Add midroll
            Log.v(TAG, "Adding temporal slot for midrolls: duration = " + brightcoveVideoView.getDuration());
            int midrollCount = 4;
            int segmentLength = (brightcoveVideoView.getDuration() / 1000) / (midrollCount + 1);
            TemporalSlotConfiguration midrollSlot;
            for (int i = 0; i < midrollCount; i++) {
                midrollSlot = new TemporalSlotConfiguration("moe" + i, adConstants.ADUNIT_MIDROLL(), segmentLength * (i + 1));
                adRequestConfiguration.addSlotConfiguration(midrollSlot);
            }
            // Add postroll
            Log.v(TAG, "Adding temporal slot for postrolls");
            TemporalSlotConfiguration postrollSlot = new TemporalSlotConfiguration("curly", adConstants.ADUNIT_POSTROLL(), video.getDuration() / 1000);
            adRequestConfiguration.addSlotConfiguration(postrollSlot);
            // Add overlay
            Log.v(TAG, "Adding temporal slot for overlays");
            TemporalSlotConfiguration overlaySlot = new TemporalSlotConfiguration("shemp", adConstants.ADUNIT_OVERLAY(), 8);
            adRequestConfiguration.addSlotConfiguration(overlaySlot);
        }
    });
    freeWheelController.enable();
}
Also used : ViewGroup(android.view.ViewGroup) ISlot(tv.freewheel.ad.interfaces.ISlot) AdRequestConfiguration(tv.freewheel.ad.request.config.AdRequestConfiguration) TemporalSlotConfiguration(tv.freewheel.ad.request.config.TemporalSlotConfiguration) NonTemporalSlotConfiguration(tv.freewheel.ad.request.config.NonTemporalSlotConfiguration) IConstants(tv.freewheel.ad.interfaces.IConstants) IAdContext(tv.freewheel.ad.interfaces.IAdContext) FreeWheelController(com.brightcove.freewheel.controller.FreeWheelController) Video(com.brightcove.player.model.Video) NonTemporalSlotConfiguration(tv.freewheel.ad.request.config.NonTemporalSlotConfiguration) Event(com.brightcove.player.event.Event) List(java.util.List) EventListener(com.brightcove.player.event.EventListener) VideoAssetConfiguration(tv.freewheel.ad.request.config.VideoAssetConfiguration)

Example 20 with Event

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

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