Play VOD streams registered with Google Cloud Video Stitcher API

This guide demonstrates how to use the IMA DAI SDK for iOS 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

User context
The user context for tracking requests.Can be nil. Defaults to nil in this guide.

Set up the basic example

Go to the IMA iOS DAI Github release page and download the basic ObjC example. This example is an iOS Xcode project that relies on Cocoapods to load the IMA SDK. If you are using Swift, IMA does not have an iOS sample app but see the Swift code snippet below for how to implement an IMAVideoStitcherVODStreamRequest in your own app.

To prepare the sample to run, make sure CocoaPods is installed, then open the basic example's folder in the terminal and run the following command:

pod install --repo-update

Once that command completes, you see a file named BasicExample.xcworkspace in your project folder. Open this file in Xcode and run the sample to ensure that the test video and ads play as expected.

Request a VOD stream

To replace the sample stream with your ad stitched VOD stream, use IMAVideoStitcherVODStreamRequest 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.

In the existing sample, there are examples for requesting a VOD stream or a live stream from Google's DAI servers. To make it work with the Google Cloud Video Stitcher API, you need to replace the current requestStream function with one that uses the IMAVideoStitcherVODStreamRequest class.

Here's an example:

ObjC

ViewController.m

...
#​import <GoogleInteractiveMediaAds/GoogleInteractiveMediaAds.h>
/// Fallback URL in case something goes wrong in loading the stream. If all goes well, /// this will not be used. static NSString *const kTestAppContentUrl_M3U8 = @"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8";
static NSString *const kContentSourceUrl = @"CONTENT_SOURCE_URL"; static NSString *const kAdTagUrl = @"AD_TAG_URL"; static NSString *const kLocation = @"LOCATION"; static NSString *const kProjectNumber = @"PROJECT_NUMBER"; static NSString *const kOAuthToken = @"OAUTH_TOKEN"; static NSString *const kNetworkCode = @"NETWORKCODE";
@interface ViewController () ...
-​ (void)requestStream { // Create an ad display container for ad rendering. IMAAdDisplayContainer *adDisplayContainer = [[IMAAdDisplayContainer alloc] initWithAdContainer:self.videoView viewController:self companionSlots:nil]; // Create an IMAAVPlayerVideoDisplay to give the SDK access to your video player. IMAAVPlayerVideoDisplay *imaVideoDisplay = [[IMAAVPlayerVideoDisplay alloc] initWithAVPlayer:self.contentPlayer];
IMAVideoStitcherVODStreamRequest *request = [[IMAVideoStitcherVODStreamRequest alloc] initWithAdTagURL:kAdTagUrl region:kLocation projectNumber:kProjectNumber OAuthToken:kOAuthToken networkCode:kNetworkCode contentSourceURL:kContentSourceUrl adDisplayContainer:adDisplayContainer videoDisplay:imaVideoDisplay userContext:nil];
[self.adsLoader requestStreamWithRequest:request]; } ...

Swift

file where AdsLoader.requestStream() is called.

func requestStream() {
guard let avPlayer = playerViewController.player else { return }
self.videoDisplay = IMAAVPlayerVideoDisplay(avPlayer: avPlayer)
videoDisplay!.playerVideoDisplayDelegate = self
let request: IMAStreamRequest
request = IMAVideoStitcherVODStreamRequest( adTagURL:@"AD_TAG_URL", region:@"LOCATION" projectNumber:@"PROJECT_NUMBER" OAuthToken:@"OAUTH_TOKEN" networkCode:@"NETWORK_CODE" contentSourceURL:@"CONTENT_SOURCE_URL" adDisplayContainer:adDisplayContainer videoDisplay:imaVideoDisplay userContext:nil) self.adsLoader!.requestStream(with: request) }

Run the project, then you can 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 iOS, it's important to clean up any serving resources.

Follow the VOD clean up guide to remove any unneeded resources and assets.