Google Dynamic Ad Insertion (DAI) on Android
Google Dynamic Ad Insertion (DAI) is a Server-Side Ad-Insertion solution offered by Google where THEOplayer offers playback for HLS and DASH streams.
Using Google DAI in the Android SDK consists of 3 steps.
Importing the Google DAI feature module
Add implementation 'com.theoplayer.theoplayer-sdk-android:integration-ads-dai:+' to your module build.gradle file, as demonstrated below:
dependencies {
// ...
implementation 'com.theoplayer.theoplayer-sdk-android:core:+'
implementation 'com.theoplayer.theoplayer-sdk-android:integration-ads-dai:+'
// ...
}
Creating an instance of the Google DAI integration
If you're using automatic integrations, you can skip this step.
Create a GoogleDaiIntegration through the GoogleDaiIntegrationFactory, and add it to your player instance, as demonstrated below:
val theoplayerView = THEOplayerView(context)
val daiIntegration = GoogleDaiIntegrationFactory.createGoogleDaiIntegration(theoplayerView)
theoplayerView.player.addIntegration(daiIntegration)
Using a Google DAI source
Use a GoogleDaiVodConfiguration
or GoogleDaiLiveConfiguration
to create a GoogleDaiTypedSource to request stream, as demonstrated below:
theoplayerView.player.source = SourceDescription.Builder(
GoogleDaiTypedSource.Builder(
GoogleDaiVodConfiguration.Builder("api_key", "content_source_id", "video_id")
.build()
)
.type(SourceType.DASH)
.build()
).build()
or:
theoplayerView.player.source = SourceDescription.Builder(
GoogleDaiTypedSource.Builder(
GoogleDaiLiveConfiguration.Builder("api_key", "asset_key")
.build()
)
.type(SourceType.DASH)
.build()
).build()
Notes
The Google DAI integration exposes events through the Ads API. More information is available at How to subscribe to ad events.
The integration exposes a number of additional methods.
These are available directly on the GoogleDaiIntegration object,
or indirectly through player.ads.dai (only for Kotlin).
For example:
- requestStream(StreamRequest, AdsRenderingSettings) can be used to request stream through the native Google DAI API.
- contentTimeForStreamTime(double) / streamTimeForContentTime(double) can be used to convert content time to stream time and vice versa.