Search in sources :

Example 6 with EventListener

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

the class MainActivity method setupFreeWheel.

private void setupFreeWheel() {
    //change this to new FrameLayout based constructor.
    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 = (ViewGroup) 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();
            // This overrides what the plugin does by default for setVideoAsset() which is to pass in currentVideo.getId().
            // video ID
            adContext.setVideoAsset(// video ID
            "3pqa_video", // FW uses their duration as seconds; Android is in milliseconds
            video.getDuration() / 1000, // location
            null, // auto play type
            adConstants.VIDEO_ASSET_AUTO_PLAY_TYPE_ATTENDED(), // a random number
            (int) Math.floor(Math.random() * Integer.MAX_VALUE), // setting networkId for 0 as it's the default value for this method
            0, // type of video ID passed (customer created or FW issued)
            adConstants.ID_TYPE_CUSTOM(), // fallback ID
            0, // duration type
            adConstants.VIDEO_ASSET_DURATION_TYPE_EXACT());
            adContext.addSiteSectionNonTemporalSlot("300x250slot", null, 300, 250, null, true, null, null);
            // Add preroll
            Log.v(TAG, "Adding temporal slot for prerolls");
            adContext.addTemporalSlot("larry", "PREROLL", 0, null, 0, 0, null, null, 0);
            // Add midroll
            Log.v(TAG, "Adding temporal slot for midrolls");
            int midrollCount = 1;
            int segmentLength = (video.getDuration() / 1000) / (midrollCount + 1);
            for (int i = 0; i < midrollCount; i++) {
                adContext.addTemporalSlot("moe" + i, "MIDROLL", segmentLength * (i + 1), null, 0, 0, null, null, 0);
            }
            // Add postroll
            Log.v(TAG, "Adding temporal slot for postrolls");
            adContext.addTemporalSlot("curly", "POSTROLL", video.getDuration() / 1000, null, 0, 0, null, null, 0);
            // Add overlay
            Log.v(TAG, "Adding temporal slot for overlays");
            adContext.addTemporalSlot("shemp", "OVERLAY", 8, null, 0, 0, null, null, 0);
        }
    });
    freeWheelController.enable();
}
Also used : IConstants(tv.freewheel.ad.interfaces.IConstants) IAdContext(tv.freewheel.ad.interfaces.IAdContext) FreeWheelController(com.brightcove.freewheel.controller.FreeWheelController) ViewGroup(android.view.ViewGroup) Video(com.brightcove.player.model.Video) Event(com.brightcove.player.event.Event) List(java.util.List) EventListener(com.brightcove.player.event.EventListener) ISlot(tv.freewheel.ad.interfaces.ISlot)

Example 7 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) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    brightcoveVideoView.getEventEmitter().on(EventType.DID_SET_SOURCE, new EventListener() {

        @Override
        public void processEvent(Event event) {
            ExoPlayerVideoDisplayComponent exoPlayerVideoDisplayComponent = (ExoPlayerVideoDisplayComponent) brightcoveVideoView.getVideoDisplay();
            exoPlayerVideoDisplayComponent.setMetadataListener(new ExoPlayerVideoDisplayComponent.Id3MetadataListener() {

                @Override
                public void onId3Metadata(List<Id3Frame> list) {
                    for (Id3Frame id3Frame : list) {
                        Log.v(TAG, "id3 Frame id: " + id3Frame.id);
                    }
                }
            });
        }
    });
    Video video = Video.createVideo("https://s3.amazonaws.com/as-zencoder/hls-timed-metadata/test.m3u8");
    brightcoveVideoView.add(video);
    brightcoveVideoView.start();
    // Log whether or not instance state in non-null.
    if (savedInstanceState != null) {
        Log.v(TAG, "Restoring saved position");
    } else {
        Log.v(TAG, "No saved state");
    }
}
Also used : Video(com.brightcove.player.model.Video) Event(com.brightcove.player.event.Event) List(java.util.List) EventListener(com.brightcove.player.event.EventListener) Id3Frame(com.google.android.exoplayer.metadata.id3.Id3Frame) ExoPlayerVideoDisplayComponent(com.brightcove.player.display.ExoPlayerVideoDisplayComponent)

Example 8 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) {
    setContentView(R.layout.activity_main);
    brightcoveVideoView = (BrightcoveVideoView) findViewById(R.id.brightcove_video_view);
    super.onCreate(savedInstanceState);
    brightcoveVideoView.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.sintel_trailer));
    BrightcoveCaptionFormat brightcoveCaptionFormat = BrightcoveCaptionFormat.createCaptionFormat("text/vtt", "de");
    brightcoveVideoView.addSubtitleSource(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.sintel_trailer_de), brightcoveCaptionFormat);
    brightcoveCaptionFormat = BrightcoveCaptionFormat.createCaptionFormat("text/vtt", "en");
    brightcoveVideoView.addSubtitleSource(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.sintel_trailer_en), brightcoveCaptionFormat);
    brightcoveCaptionFormat = BrightcoveCaptionFormat.createCaptionFormat("text/vtt", "es");
    brightcoveVideoView.addSubtitleSource(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.sintel_trailer_es), brightcoveCaptionFormat);
    brightcoveCaptionFormat = BrightcoveCaptionFormat.createCaptionFormat("text/vtt", "fr");
    brightcoveVideoView.addSubtitleSource(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.sintel_trailer_fr), brightcoveCaptionFormat);
    brightcoveCaptionFormat = BrightcoveCaptionFormat.createCaptionFormat("text/vtt", "it");
    brightcoveVideoView.addSubtitleSource(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.sintel_trailer_it), brightcoveCaptionFormat);
    brightcoveCaptionFormat = BrightcoveCaptionFormat.createCaptionFormat("text/vtt", "nl");
    brightcoveVideoView.addSubtitleSource(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.sintel_trailer_nl), brightcoveCaptionFormat);
    brightcoveVideoView.getEventEmitter().once(EventType.CAPTIONS_LANGUAGES, new EventListener() {

        @Override
        public void processEvent(Event event) {
            brightcoveVideoView.setClosedCaptioningEnabled(true);
            brightcoveVideoView.setSubtitleLocale("en");
        }
    });
}
Also used : BrightcoveCaptionFormat(com.brightcove.player.captioning.BrightcoveCaptionFormat) Event(com.brightcove.player.event.Event) EventListener(com.brightcove.player.event.EventListener)

Example 9 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 10 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)22 EventListener (com.brightcove.player.event.EventListener)22 ArrayList (java.util.ArrayList)7 ViewGroup (android.view.ViewGroup)6 GoogleIMAComponent (com.brightcove.ima.GoogleIMAComponent)6 Video (com.brightcove.player.model.Video)6 AdDisplayContainer (com.google.ads.interactivemedia.v3.api.AdDisplayContainer)6 AdsRequest (com.google.ads.interactivemedia.v3.api.AdsRequest)6 ImaSdkFactory (com.google.ads.interactivemedia.v3.api.ImaSdkFactory)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 Instrumentation (android.app.Instrumentation)2 View (android.view.View)2 BrightcoveMediaController (com.brightcove.player.mediacontroller.BrightcoveMediaController)2 Source (com.brightcove.player.model.Source)2 BrightcoveVideoView (com.brightcove.player.view.BrightcoveVideoView)2