andrewlewis eb9de7a120 Fix postroll content complete notifications
On reaching the end of the content we would notify content complete
and skip unplayed ads, causing a timeline change. That timeline change
was handled in a way that caused a further timeline change in the
2.11.6 release, where we don't yet deduplicate no-op Timeline changes,
causing repeated timeline changes indefinitely.

At tip-of-tree, the timeline wouldn't refresh repeatedly. However the
code for sending content complete at the point of transitioning to
play a preloaded postroll ad was not correct in that it didn't mark
previous ads as skipped. Instead they happened to be marked as
skipped later on due to the timeline change handling content
completion code triggering again.

Fix this by only marking ads as skipped when content completes once,
to avoid the duplicate timeline change, and moving the skipped ad
marking so it happens in the same place as notifying content complete.

PiperOrigin-RevId: 318454908
2020-06-26 13:46:53 +01:00
..
2020-02-13 15:45:30 +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:

implementation 'com.google.android.exoplayer:extension-ima:2.X.X'

where 2.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. Note that the IMA extension only supports players which are accessed on the application's main thread.

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.