andrewlewis 5c49633c30 Fix ad group skipping
Allow skipping an ad group when requested by IMA, even if we aren't currently
playing one, to handle cases where no ads in an ad group will load (so IMA
requests resuming content but we never managed to start playing an ad).

Use the known ad group index (rather than the expected one) when handling ad
group load errors. This ensures we skip the right ad group if we notify IMA of
playback errors for every ad in the ad group, then IMA notifies that the ad
group is empty via a load error.

Also make some other miscellaneous small fixes to ads code:

- Avoid warning about unexpected ad group indices more than once.
- Output a warning if the ad count in an ad group decreases.
- Remove unnecessary assertion.
- Fix getting the ad duration for ad indices that haven't loaded yet.
- Allow setting an ad group state to its current value.
- Fix javadoc for setting the ad resume position.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=184831495
2018-02-20 10:45:26 +00:00
..
2018-02-20 10:45:26 +00:00
2017-11-20 13:39:03 +00:00

ExoPlayer IMA extension

The IMA extension is an AdsLoader implementation wrapping the Interactive Media Ads SDK for Android. You can use it to insert ads alongside content.

Getting the extension

The easiest way to use the extension is to add it as a gradle dependency:

compile 'com.google.android.exoplayer:extension-ima:rX.X.X'

where rX.X.X is the version, which must match the version of the ExoPlayer library being used.

Alternatively, you can clone the ExoPlayer repository and depend on the module locally. Instructions for doing this can be found in ExoPlayer's top level README.

Using the extension

To play ads alongside a single-window content MediaSource, prepare the player with an AdsMediaSource constructed using an ImaAdsLoader, the content MediaSource and an overlay ViewGroup on top of the player. Pass an ad tag URI from your ad campaign when creating the ImaAdsLoader. The IMA documentation includes some sample ad tags for testing.

Resuming the player after entering the background requires some special handling when playing ads. The player and its media source are released on entering the background, and are recreated when the player returns to the foreground. When playing ads it is necessary to persist ad playback state while in the background by keeping a reference to the ImaAdsLoader. Reuse it when resuming playback of the same content/ads by passing it in when constructing the new AdsMediaSource. It is also important to persist the player position when entering the background by storing the value of player.getContentPosition(). On returning to the foreground, seek to that position before preparing the new player instance. Finally, it is important to call ImaAdsLoader.release() when playback of the content/ads has finished and will not be resumed.

You can try the IMA extension in the ExoPlayer demo app. To do this you must select and build one of the withExtensions build variants of the demo app in Android Studio. You can find IMA test content in the "IMA sample ad tags" section of the app. The demo app's PlayerActivity also shows how to persist the ImaAdsLoader instance and the player position when backgrounded during ad playback.

  • Javadoc: Classes matching com.google.android.exoplayer2.ext.ima.* belong to this module.