# ExoPlayer IMA Extension - DAI

ATTENTION

The Unified Plugin does not support CDN Balancer module for ExoPlayer IMA Extensions

The Unified Plugin supports Ad Analytics for ExoPlayer using the IMA extension with dynamic ad insertion (DAI).

# Prerequisites

  1. Unified Plugin Video Analytics is integrated with ExoPlayer:
  2. DAI integrated with Exoplayer using the ImaServerSideAdInsertionMediaSource from the ExoPlayer IMA extension:

# Install Player Adapter

Declare the following dependency:

...
implementation 'com.npaw.plugin:plugin-ima:3.29.0-7.1.2'
...
1
2
3

# Integrate Unified Plugin with Player

To collect ad metrics from ExoPlayer, create an ImaAdapter and register it as an event and error listener on your ImaServerSideAdInsertionMediaSource.AdsLoader.Builder. When building your Video instance, inject the ImaAdapter into it.

If you are using the CDN Balancer, make sure to inject its media source factory to the ImaServerSideAdInsertionMediaSource.Factory.

  • Java
  • Kotlin
// Create the IMA Adapter instance for server-side ad insertion
ImaAdapter imaAdapter = new ImaAdapter(AdAdapter.InsertionType.SERVER_SIDE);

// Ad the IMA Adapter as an event and error listener to your adsLoader
ImaServerSideAdInsertionMediaSource.AdsLoader imaServerSideAdsLoader =
    new ImaServerSideAdInsertionMediaSource.AdsLoader.Builder(this, playerView)
        .setAdEventListener(imaAdapter)
        .setAdErrorListener(imaAdapter)
        .build();

// (If using CDN Balancer) Inject our Balancer mediaSourceFactory into the IMA media source factory
ExoPlayerBalancer balancer = new ExoPlayerBalancer(unifiedPlugin);

ImaServerSideAdInsertionMediaSource.Factory imaServerSideMediaSourceFactory =
    new ImaServerSideAdInsertionMediaSource.Factory(
        imaServerSideAdsLoader, balancer.mediaSourceFactory);

...

// (If using CDN Balancer) Inject our Balancer mediaSourceFactory into the ExoPlayer instance
DefaultMediaSourceFactory mediaSourceFactory =
    balancer.mediaSourceFactory
        .setServerSideAdInsertionMediaSourceFactory(imaServerSideMediaSourceFactory);

...

ExoPlayer player = ExoPlayer.Builder(this)
    .setMediaSourceFactory(mediaSourceFactory)
    .build();

imaServerSideAdsLoader.setPlayer(player);

// Create the Video Adapter instance after building the player instance
VideoAdapter videoAdapter =
    unifiedPlugin.videoBuilder()
        .setPlayerAdapter(ExoPlayerAdapter(this, player))
        .setAdAdapter(imaAdapter)
        .build();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

At this point, your integration of the Unified Plugin is concluded.

After running your application, you should see your metrics appearing in your Codavel Panel dashboards.

# Further Customizations

The plugin allow you to configure different parameters in your integration, such as the metadata of the video playing. Detailed explanations of these options are available here.

Updated: 7/6/2023, 3:26:38 PM