Skip to main content
Skip table of contents

Adverts with Google IMA

To test this feature and view the example code, please see the Android SDK 4 Example Code Quick Start guide.

This application inserts adverts using the IMAWrapper class via the Google Interactive Media Ads (IMA) SDK to access ad servers that support VAST and VMAP.

Linear adverts are video adverts inserted, cutting off VOD playback, or interrupting live playback.

Companion adverts are images displayed in views accompanying the video playback.

For more information, see:

Prerequisites

An ad server already configured and knowledge of the ad tag URLs that will be used to access it.

Procedure

The main stages are as follows:

Project setup

The following instructions show you how to modify your existing application to make use of the IMAWrapper package with the Google IMA libraries.

  1. Unzip the supplied example code zip file and extract the dynamic-ads-ima folder. This folder contains an Android Studio project for building example code with adverts fetched from a demo ad-server.

    • The project is based on the basic-playback project, with ad support built on top of it.
    • Within the Java source code of the project, the adverts folder contains the IMAWrapper package (in source-code) provided by Nagra. This package simplifies configuration and access to an ad-server, as well as playback and display of the adverts.
    • You may build upon this code, or use it as a reference for your application. See the Android SDK4 Integration Guide for more details.


  2. In the application project you are building, update your Gradle script to fetch the Google IMA Play Services libraries from the Google Maven repository. Add the repository:

    GROOVY
    repositories {
      jcenter()
      mavenCentral()
    
    ... << other repositories omitted >> ...
    
      maven {
        url "https://maven.google.com/"
      }
    }

    Add the following third-party dependencies:

    GROOVY
    ... <<details omitted >> ...
    
    dependencies {
      ... << other dependencies omitted >> ...
    
     implementation 'com.google.ads.interactivemedia.v3:interactivemedia:3.11.3'
      implementation 'com.google.android.gms:play-services-ads:11.8.0'
    }

    There is the potential for a clash between the versions of play-services-ads and play-services-cast-framework dependencies. Ideally the version of play-services-ads should be the latest from the v11 series (11.8.0), but for this to align with the same version of play-services-cast-framework in an application, it means the Android build tools version needs to be 27.

Next step: Enable playback of linear adverts

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.