Search in sources :

Example 1 with AdsManager

use of com.google.ads.interactivemedia.v3.api.AdsManager in project ExoPlayer by google.

the class AdTagLoader method handleAdPrepareError.

private void handleAdPrepareError(int adGroupIndex, int adIndexInAdGroup, Exception exception) {
    if (configuration.debugModeEnabled) {
        Log.d(TAG, "Prepare error for ad " + adIndexInAdGroup + " in group " + adGroupIndex, exception);
    }
    if (adsManager == null) {
        Log.w(TAG, "Ignoring ad prepare error after release");
        return;
    }
    if (imaAdState == IMA_AD_STATE_NONE) {
        // Send IMA a content position at the ad group so that it will try to play it, at which point
        // we can notify that it failed to load.
        fakeContentProgressElapsedRealtimeMs = SystemClock.elapsedRealtime();
        fakeContentProgressOffsetMs = Util.usToMs(adPlaybackState.getAdGroup(adGroupIndex).timeUs);
        if (fakeContentProgressOffsetMs == C.TIME_END_OF_SOURCE) {
            fakeContentProgressOffsetMs = contentDurationMs;
        }
        pendingAdPrepareErrorAdInfo = new AdInfo(adGroupIndex, adIndexInAdGroup);
    } else {
        AdMediaInfo adMediaInfo = checkNotNull(imaAdMediaInfo);
        // We're already playing an ad.
        if (adIndexInAdGroup > playingAdIndexInAdGroup) {
            // which means that the ad after will load (if any).
            for (int i = 0; i < adCallbacks.size(); i++) {
                adCallbacks.get(i).onEnded(adMediaInfo);
            }
        }
        playingAdIndexInAdGroup = adPlaybackState.getAdGroup(adGroupIndex).getFirstAdIndexToPlay();
        for (int i = 0; i < adCallbacks.size(); i++) {
            adCallbacks.get(i).onError(checkNotNull(adMediaInfo));
        }
    }
    adPlaybackState = adPlaybackState.withAdLoadError(adGroupIndex, adIndexInAdGroup);
    updateAdPlaybackState();
}
Also used : AdMediaInfo(com.google.ads.interactivemedia.v3.api.player.AdMediaInfo)

Example 2 with AdsManager

use of com.google.ads.interactivemedia.v3.api.AdsManager in project ExoPlayer by google.

the class AdTagLoader method activate.

/**
 * Activates playback.
 */
public void activate(Player player) {
    this.player = player;
    player.addListener(this);
    boolean playWhenReady = player.getPlayWhenReady();
    onTimelineChanged(player.getCurrentTimeline(), Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE);
    @Nullable AdsManager adsManager = this.adsManager;
    if (!AdPlaybackState.NONE.equals(adPlaybackState) && adsManager != null && imaPausedContent) {
        // Check whether the current ad break matches the expected ad break based on the current
        // position. If not, discard the current ad break so that the correct ad break can load.
        long contentPositionMs = getContentPeriodPositionMs(player, timeline, period);
        int adGroupForPositionIndex = adPlaybackState.getAdGroupIndexForPositionUs(Util.msToUs(contentPositionMs), Util.msToUs(contentDurationMs));
        if (adGroupForPositionIndex != C.INDEX_UNSET && imaAdInfo != null && imaAdInfo.adGroupIndex != adGroupForPositionIndex) {
            if (configuration.debugModeEnabled) {
                Log.d(TAG, "Discarding preloaded ad " + imaAdInfo);
            }
            adsManager.discardAdBreak();
        }
        if (playWhenReady) {
            adsManager.resume();
        }
    }
}
Also used : AdsManager(com.google.ads.interactivemedia.v3.api.AdsManager) Nullable(androidx.annotation.Nullable)

Example 3 with AdsManager

use of com.google.ads.interactivemedia.v3.api.AdsManager in project ExoPlayer by google.

the class AdTagLoader method onPlaybackStateChanged.

@Override
public void onPlaybackStateChanged(@Player.State int playbackState) {
    @Nullable Player player = this.player;
    if (adsManager == null || player == null) {
        return;
    }
    if (playbackState == Player.STATE_BUFFERING && !player.isPlayingAd() && isWaitingForAdToLoad()) {
        waitingForPreloadElapsedRealtimeMs = SystemClock.elapsedRealtime();
    } else if (playbackState == Player.STATE_READY) {
        waitingForPreloadElapsedRealtimeMs = C.TIME_UNSET;
    }
    handlePlayerStateChanged(player.getPlayWhenReady(), playbackState);
}
Also used : Player(com.google.android.exoplayer2.Player) VideoAdPlayer(com.google.ads.interactivemedia.v3.api.player.VideoAdPlayer) Nullable(androidx.annotation.Nullable)

Example 4 with AdsManager

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

the class PlayerFragment method onActivityCreated.

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    // 
    // IMA SDK
    // 
    // Create an AdsLoader.
    sdkFactory = ImaSdkFactory.getInstance();
    adsLoader = sdkFactory.createAdsLoader(this.getActivity());
    // Add listeners for when ads are loaded and for errors.
    adsLoader.addAdErrorListener(this);
    adsLoader.addAdsLoadedListener(new AdsLoader.AdsLoadedListener() {

        @Override
        public void onAdsManagerLoaded(AdsManagerLoadedEvent adsManagerLoadedEvent) {
            // Ads were successfully loaded, so get the AdsManager instance. AdsManager has
            // events for ad playback and errors.
            adsManager = adsManagerLoadedEvent.getAdsManager();
            // Attach event and error event listeners.
            adsManager.addAdErrorListener(PlayerFragment.this);
            adsManager.addAdEventListener(PlayerFragment.this);
            adsManager.init();
        }
    });
    sensorViewModel = ViewModelProviders.of(getActivity()).get(SensorViewModel.class);
    videoDetailViewModel = ViewModelProviders.of(getActivity()).get(VideoDetailViewModel.class);
    if (playerViewModel.isTrailer().getValue()) {
        ImageButton buttonCloseTrailer = getView().findViewById(R.id.buttonCloseTrailer);
        buttonCloseTrailer.setVisibility(View.VISIBLE);
        buttonCloseTrailer.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                stop();
                videoDetailViewModel.onVideoFinished(true);
                playerViewModel.setTrailerVideoId(null);
            }
        });
    }
    setHasOptionsMenu(true);
}
Also used : ImageButton(android.widget.ImageButton) AdsManagerLoadedEvent(com.google.ads.interactivemedia.v3.api.AdsManagerLoadedEvent) VideoDetailViewModel(com.zype.android.ui.video_details.VideoDetailViewModel) ImageView(android.widget.ImageView) SurfaceView(android.view.SurfaceView) View(android.view.View) AdsLoader(com.google.ads.interactivemedia.v3.api.AdsLoader)

Example 5 with AdsManager

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

Aggregations

Nullable (androidx.annotation.Nullable)4 AdsManager (com.google.ads.interactivemedia.v3.api.AdsManager)4 VideoAdPlayer (com.google.ads.interactivemedia.v3.api.player.VideoAdPlayer)3 Player (com.google.android.exoplayer2.Player)3 BrightcoveMediaController (com.brightcove.player.mediacontroller.BrightcoveMediaController)2 AdMediaInfo (com.google.ads.interactivemedia.v3.api.player.AdMediaInfo)2 SurfaceView (android.view.SurfaceView)1 View (android.view.View)1 ImageButton (android.widget.ImageButton)1 ImageView (android.widget.ImageView)1 Event (com.brightcove.player.event.Event)1 EventListener (com.brightcove.player.event.EventListener)1 Catalog (com.brightcove.player.media.Catalog)1 VideoListener (com.brightcove.player.media.VideoListener)1 BrightcoveSeekBar (com.brightcove.player.mediacontroller.BrightcoveSeekBar)1 Video (com.brightcove.player.model.Video)1 AdsLoader (com.google.ads.interactivemedia.v3.api.AdsLoader)1 AdsManagerLoadedEvent (com.google.ads.interactivemedia.v3.api.AdsManagerLoadedEvent)1 AdsRenderingSettings (com.google.ads.interactivemedia.v3.api.AdsRenderingSettings)1 AdPlaybackState (com.google.android.exoplayer2.source.ads.AdPlaybackState)1