Limited Availability - Do not share this document

Migrating to Brightcove's IMA Plugin 8.0.0

In this topic, you will learn how to migrate your app to use Brightcove's IMA plugin for the Native SDK for Android 8.0.0.

Overview

The Brightcove Native SDK for Android 8.0.0 or later supports the Google IMA SDK version 3.27.1. If you are using IMA advertising, there are a few things to be aware of to use this version of the IMA plugin. They include the following:

Changes in the Google IMA SDK

The Brightcove Native SDK updated the Google IMA SDK from version 3.11.2 to version 3.27.1. The most relevant changes include:

  • SdkFactory.createAdDisplayContainer() is deprecated
  • AdDisplayContainer.setPlayer(VideoAdPlayer) is deprecated
  • AdDisplayContainer.setAdContainer(ViewGroup) is deprecated
  • AdsRequest.setAdDisplayContainer(AdDisplayContainer) is removed

For the full release, see the Google IMA Android SDK release history document.

Changes in the Brightcove IMA plugin

The Brightcove IMA plugin made several changes to be fully compatible with the new Google IMA SDK version. They include:

Using the GoogleIMAComponent Builder

We recommend using the Builder to create the GoogleIMAComponent instance. This makes it easier to configure the GoogleIMAComponent.

googleIMAComponent = new GoogleIMAComponent.Builder(brightcoveVideoView, eventEmitter)
  .setUseAdRules(true)
  .setImaSdkSettings(customIMASDKSettings)
  .setAdsRenderingSettings(customAdsRenderingSettings)
  .setAdDisplayContainerFactory(customAdDisplayContainerFactory)
  .build();
}

Creating the AdDisplayContainer

Because the Google IMA SDK removed AdsRequest.setAdDisplayContainer(...), the Brightcove IMA plugin now creates this automatically, using the GoogleIMAVideoAdPlayer and the BaseVideoView.

The plugin requires an AdDisplayContainerFactory to create the AdDisplayContainer.

public interface AdDisplayContainerFactory {
  /**
  * Creates the AdDisplayContainer with the provided GoogleIMAVideoAdPlayer
  * and the ViewGroup retrieved with getViewContainer()
  *
  * @param googleIMAVideoAdPlayer the Brightcove Ad Player for Google IMA
  */
  AdDisplayContainer createAdDisplayContainer(GoogleIMAVideoAdPlayer googleIMAVideoAdPlayer);

  /**
  * Returns the ViewGroup container used for both,
  * the creation of the GoogleIMAVideoAdPlayer and the AdDisplayContainer
  */
  ViewGroup getViewContainer();
}

Under the hood, the plugin uses the DefaultAdDisplayContainerFactory, an AdDisplayContainerFactory, to create the AdDisplayContainer. The getViewContainer() returns the BaseVideoView passed in its constructor, and the createAdDisplayContainer method returns:

ImaSdkFactory.createAdDisplayContainer(getViewContainer(), googleIMAVideoAdPlayer);

Add your AdDisplayContainerFactory

If you need a different implementation, you must pass your own AdDisplayContainerFactory to the GoogleIMAComponent Builder:

googleIMAComponent = new GoogleIMAComponent.Builder(brightcoveVideoView, eventEmitter)
  .setAdDisplayContainerFactory(customAdDisplayContainerFactory)
  .build();

If you want to play the Ads in a different view other than the BaseVideoView, you can provide the DefaultAdDisplayContainerFactory with your ViewGroup.

googleIMAComponent = new GoogleIMAComponent.Builder(brightcoveVideoView, eventEmitter)
  .setAdDisplayContainerFactory(new DefaultAdDisplayContainerFactory(myViewGroup))
  .build();

Deprecated methods in GoogleIMAVideoAdPlayer

The following methods are deprecated in the GoogleIMAVideoAdPlayer class:

Deprecated method Use instead
playAd() playAd(AdMediaInfo)
loadAd(String) loadAd(AdMediaInfo, AdPodInfo)
stopAd() stopAd(AdMediaInfo)
resumeAd() playAd(AdMediaInfo)
pauseAd() pauseAd(AdMediaInfo)

Notice that the replacement methods now require AdMediaInfo. You can retrieve the current AdMediaInfo object by calling GoogleIMAVideoAdPlayer.getCurrentAdMediaInfo(). This will return the loaded AdMediaInfo, or Null.

Migrating to the IMA Plugin 8.0.0

To migrate to the Brightcove IMA Plugin 8.0.0, follow steps:

Update dependency versions

Update your app to use the following dependency versions:

  • All of the Brightcove SDK dependencies set to version 8.0.0
  • Use Google IMA SDK version 3.27.1

Here is an example of the build.gradle file:

//build.gradle
dependencies {
 //Brightcove SDK dependencies
 implementation "com.brightcove.player:android-sdk8.0.0:"
 implementation "com.brightcove.player:exoplayer2:8.0.0"
 implementation "com.brightcove.player:android-ima-plugin:8.0.0"

 //Google IMA SDK
 implementation "com.google.ads.interactivemedia.v3:interactivemedia:3.27.1"
 ...
}

Remove deprecated methods

Your current Google IMA setup might look similar to this:

AdDisplayContainer container = sdkFactory.createAdDisplayContainer();
container.setPlayer(googleIMAComponent.getVideoAdPlayer());
container.setAdContainer(brightcoveVideoView);

These three methods are deprecated and will go away.

You must now call googleIMAComponent.getAdDisplayContainer() and it will return the AdDisplayContainer associated with the GoogleIMAVideoAdPlayer, or null if not available.

For details about creating the AdDisplayContainer, see the Creating the AdDisplayContainer section.

The following method has also been removed from the Google IMA SDK:

adsRequest.setAdDisplayContainer(container);

Instead, use the AdDisplayContainer to create an instance of the Google IMA AdsLoader.

For details about deprecated methods and their replacements, see the Deprecated methods in GoogleIMAVideoAdPlayer section.

More information

For more details about IMA changes, see the Google IMA Android SDK release history documentation.