Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | - | - | ||||
src/ | 23-Nov-2023 | - | 2,803 | 2,063 | ||
README.md | D | 23-Nov-2023 | 3.1 KiB | 67 | 50 | |
build.gradle | D | 23-Nov-2023 | 2.5 KiB | 66 | 57 | |
proguard-rules.txt | D | 23-Nov-2023 | 239 | 7 | 5 |
README.md
1# ExoPlayer IMA extension # 2 3The IMA extension is an [AdsLoader][] implementation wrapping the 4[Interactive Media Ads SDK for Android][IMA]. You can use it to insert ads 5alongside content. 6 7[IMA]: https://developers.google.com/interactive-media-ads/docs/sdks/android/ 8[AdsLoader]: https://exoplayer.dev/doc/reference/index.html?com/google/android/exoplayer2/source/ads/AdsLoader.html 9 10## Getting the extension ## 11 12The easiest way to use the extension is to add it as a gradle dependency: 13 14```gradle 15implementation 'com.google.android.exoplayer:extension-ima:2.X.X' 16``` 17 18where `2.X.X` is the version, which must match the version of the ExoPlayer 19library being used. 20 21Alternatively, you can clone the ExoPlayer repository and depend on the module 22locally. Instructions for doing this can be found in ExoPlayer's 23[top level README][]. 24 25[top level README]: https://github.com/google/ExoPlayer/blob/release-v2/README.md 26 27## Using the extension ## 28 29To play ads alongside a single-window content `MediaSource`, prepare the player 30with an `AdsMediaSource` constructed using an `ImaAdsLoader`, the content 31`MediaSource` and an overlay `ViewGroup` on top of the player. Pass an ad tag 32URI from your ad campaign when creating the `ImaAdsLoader`. The IMA 33documentation includes some [sample ad tags][] for testing. Note that the IMA 34extension only supports players which are accessed on the application's main 35thread. 36 37Resuming the player after entering the background requires some special handling 38when playing ads. The player and its media source are released on entering the 39background, and are recreated when the player returns to the foreground. When 40playing ads it is necessary to persist ad playback state while in the background 41by keeping a reference to the `ImaAdsLoader`. Reuse it when resuming playback of 42the same content/ads by passing it in when constructing the new 43`AdsMediaSource`. It is also important to persist the player position when 44entering the background by storing the value of `player.getContentPosition()`. 45On returning to the foreground, seek to that position before preparing the new 46player instance. Finally, it is important to call `ImaAdsLoader.release()` when 47playback of the content/ads has finished and will not be resumed. 48 49You can try the IMA extension in the ExoPlayer demo app. To do this you must 50select and build one of the `withExtensions` build variants of the demo app in 51Android Studio. You can find IMA test content in the "IMA sample ad tags" 52section of the app. The demo app's `PlayerActivity` also shows how to persist 53the `ImaAdsLoader` instance and the player position when backgrounded during ad 54playback. 55 56[top level README]: https://github.com/google/ExoPlayer/blob/release-v2/README.md 57[sample ad tags]: https://developers.google.com/interactive-media-ads/docs/sdks/android/tags 58 59## Links ## 60 61* [ExoPlayer documentation on ad insertion][] 62* [Javadoc][]: Classes matching `com.google.android.exoplayer2.ext.ima.*` 63 belong to this module. 64 65[ExoPlayer documentation on ad insertion]: https://exoplayer.dev/ad-insertion.html 66[Javadoc]: https://exoplayer.dev/doc/reference/index.html 67