Dev guide: Copy editing

Also changed the links that describe configuring the
player for ad insertion to link to the ads page.

PiperOrigin-RevId: 331349846
This commit is contained in:
olly 2020-09-12 22:57:39 +01:00 committed by Oliver Woodman
parent 5a009ab476
commit b999977c9d

View File

@ -26,39 +26,30 @@ locally. Instructions for doing this can be found in ExoPlayer's
## Using the extension ## ## Using the extension ##
To play a media item with an ad tag URI, you need to customize the To use the extension, follow the instructions on the
`DefaultMediaSourceFactory` as [Ad insertion page](https://exoplayer.dev/ad-insertion.html#declarative-ad-support)
[documented in the Developer Guide](https://exoplayer.dev/media-sources.html#customizing-media-source-creation). of the developer guide. The `AdsLoaderProvider` passed to the player's
This way the player will build an `AdsMediaSource` and configure it with the `DefaultMediaSourceFactory` should return an `ImaAdsLoader`. Note that the IMA
`ImaAdsLoader` and an `AdViewProvider` automatically. extension only supports players which are accessed on the application's main
[Pass an ad tag URI](https://exoplayer.dev/media-items.html#ad-insertion) from
your ad campaign to the `MediaItem.Builder` when building your media item. 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. thread.
Resuming the player after entering the background requires some special handling 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 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 background, and are recreated when returning to the foreground. When playing ads
playing ads it is necessary to persist ad playback state while in the background it is necessary to persist ad playback state while in the background by keeping
by keeping a reference to the `ImaAdsLoader`. Reuse this instance when your a reference to the `ImaAdsLoader`. When re-entering the foreground, pass the
callback `AdsLoaderProvider.getAdsLoader(Uri adTagUri)` is called by the player same instance back when `AdsLoaderProvider.getAdsLoader(Uri adTagUri)` is called
to get an `ImaAdsLoader` for the same content/ads to be resumed. It is also to restore the state. It is also important to persist the player position when
important to persist the player position when entering the background by storing entering the background by storing the value of `player.getContentPosition()`.
the value of `player.getContentPosition()`. On returning to the foreground, seek On returning to the foreground, seek to that position before preparing the new
to that position before preparing the new player instance. Finally, it is player instance. Finally, it is important to call `ImaAdsLoader.release()` when
important to call `ImaAdsLoader.release()` when playback of the content/ads has playback has finished and will not be resumed.
finished and will not be resumed.
You can try the IMA extension in the ExoPlayer demo app, which has test content You can try the IMA extension in the ExoPlayer demo app, which has test content
in the "IMA sample ad tags" section of the sample chooser. The demo app's in the "IMA sample ad tags" section of the sample chooser. The demo app's
`PlayerActivity` also shows how to persist the `ImaAdsLoader` instance and the `PlayerActivity` also shows how to persist the `ImaAdsLoader` instance and the
player position when backgrounded during ad playback. player position when backgrounded during ad playback.
[top level README]: https://github.com/google/ExoPlayer/blob/release-v2/README.md
[sample ad tags]: https://developers.google.com/interactive-media-ads/docs/sdks/android/tags
## Links ## ## Links ##
* [ExoPlayer documentation on ad insertion][] * [ExoPlayer documentation on ad insertion][]