This guide demonstrates how to use the IMA DAI SDK for Android to request and play a Google Cloud VOD stream session.
This guide expands on the basic example from the Get started guide for IMA DAI.
For information on integrating with other platforms or on using the IMA client-side SDKs, see Interactive Media Ads SDKs.
Set up a Google Cloud project
Set up a Google Cloud project and configure service accounts to access the project.
Enter the following variables for use in the IMA SDK:
- Location
- The Google Cloud region
where your VOD config was created:
LOCATION
- Project number
- The Google Cloud project number using the Video Stitcher API:
PROJECT_NUMBER
- OAuth token
A service account's short lived OAuth token with the Video Stitcher user role:
OAUTH_TOKEN
Read more about creating short-lived OAuth tokens. The OAuth token can be reused across multiple requests as long as it has not expired.
- Network code
The Ad Manager network code for requesting ads:
NETWORK-CODE
- Ad tag URL
Ad Manager URL of the ad tag:
AD_TAG_URL
For testing, you can use the IMA VMAP Pre-roll sample.
- Content source URL
The URL string of the stream manifest for your VOD content:
CONTENT_SOURCE_URL
Set up the basic example
Go to the IMA Android DAI Github release page and download the basic example. This example is an Android app that you can open in Android Studio for testing purposes.
To test with a traditional (non-Cloud Video Stitcher) VOD stream, set the
CONTENT_TYPE
constant in SampleAdsWrapper.java to either
ContentType.VOD_HLS
, or ContentType.VOD_DASH
, to load the appropriate CMS ID
and video ID for the stream. Then in SampleVideoPlayer.java, set
currentlyPlayingStreamType
to either CONTENT_TYPE_HLS
, or
CONTENT_TYPE_DASH
,to properly handle the metadata of your chosen stream type.
If everything is working properly, clicking the play button on the video player begins the short film "Tears of Steel", with a pre-roll ad break.
Request a VOD stream
To replace the sample stream with your ad stitched VOD stream, use
sdkFactory.createVideoStitcherVodStreamRequest()
to create an ad session with Google Ad Manager. You can use the Google Ad
Manager UI to locate the generated DAI sessions for monitoring and debugging.
sdkFactory.createVideoStitcherVodStreamRequest()
is available on IMA Android
SDK v3.30.0 or higher.
In the existing sample, there are conditional statements for requesting a VOD
stream or a live stream. To make it work with the Google Cloud Video Stitcher
API, you need to add a new path to return a StreamRequest
created using
sdkFactory.createVideoStitcherVodStreamRequest()
.
Here's an example:
videoplayerapp/SampleAdsWrapper.java
... private enum ContentType { LIVE_HLS, LIVE_DASH, // Add a VOD HLS Google Cloud type. DASH streams are also supported. VOD_HLS_GOOGLE_CLOUD, VOD_DASH_GOOGLE_CLOUD, VOD_HLS, VOD_DASH, }// Set CONTENT_TYPE to the associated enum for the // stream type you would like to test. private static final ContentType CONTENT_TYPE = ContentType.VOD_HLS_GOOGLE_CLOUD; ...
@Nullable private StreamRequest buildStreamRequest() { StreamRequest request; switch (CONTENT_TYPE) { ... case VOD_HLS_GOOGLE_CLOUD: case VOD_DASH_GOOGLE_CLOUD: // VOD HLS or DASH stream generated by the // Google Cloud Video Stitcher API. request = sdkFactory.createVideoStitcherVodStreamRequest( "CONTENT_SOURCE_URL", "NETWORK_CODE", "LOCATION", "PROJECT_NUMBER", "OAUTHTOKEN", "AD_TAG_URL" ); if (CONTENT_TYPE == ContentType.VOD_HLS_GOOGLE_CLOUD) { request.setFormat(StreamFormat.HLS); } else { request.setFormat(StreamFormat.DASH); } return request; } // Content type not selected. return null; } ...
Reload the app to request and play your custom VOD stream.
Clean up
Now that you have successfully hosted a VOD stream using the Google Cloud Video Stitcher API and requested it using the IMA DAI SDK for Android, it's important to clean up any serving resources.
Follow the VOD clean up guide to remove any unneeded resources and assets.