diff --git a/ObjectiveC/BasicExample/app/ViewController.m b/ObjectiveC/BasicExample/app/ViewController.m index 83e0e7f..d7f721e 100644 --- a/ObjectiveC/BasicExample/app/ViewController.m +++ b/ObjectiveC/BasicExample/app/ViewController.m @@ -20,10 +20,18 @@ @import GoogleInteractiveMediaAds; -// Live stream asset key, VOD content source and video IDs, and backup content URL. +// Enum for stream request type, below +typedef enum {kLiveStream, kVODStream} streamType; + +/// Specifies the ad pod stream type; either `StreamType.liveStream` or `StreamType.vodStream`. +static streamType const kRequestType = kLiveStream; +/// Live stream asset key. static NSString *const kAssetKey = @"c-rArva4ShKVIAkNfy6HUQ"; -static NSString *const kContentSourceID = @"19463"; -static NSString *const kVideoID = @"googleio-highlights"; +/// VOD stream content source ID. +static NSString *const kContentSourceID = @"2548831"; +/// VOD stream video ID. +static NSString *const kVideoID = @"tears-of-steel"; +/// Backup content URL static NSString *const kBackupStreamURLString = @"http://googleimadev-vh.akamaihd.net/i/big_buck_bunny/bbb-,480p,720p,1080p,.mov.csmil/" @"master.m3u8"; @@ -87,26 +95,25 @@ - (void)requestStream { [[IMAAVPlayerVideoDisplay alloc] initWithAVPlayer:self.playerViewController.player]; self.adDisplayContainer = [[IMAAdDisplayContainer alloc] initWithAdContainer:self.adContainerView viewController:self]; - IMALiveStreamRequest *request = - [[IMALiveStreamRequest alloc] initWithAssetKey:kAssetKey - adDisplayContainer:self.adDisplayContainer - videoDisplay:self.videoDisplay - userContext:nil]; - // VOD request. Comment out the IMALiveStreamRequest above and uncomment this IMAVODStreamRequest - // to switch from a livestream to a VOD stream. - // IMAVODStreamRequest *request = - // [[IMAVODStreamRequest alloc] initWithContentSourceID:kContentSourceID - // videoID:kVideoID - // adDisplayContainer:self.adDisplayContainer - // videoDisplay:self.videoDisplay - // userContext:nil]; - [self.adsLoader requestStreamWithRequest:request]; + IMAStreamRequest *streamRequest; + if (kRequestType == kLiveStream) { + streamRequest = [[IMALiveStreamRequest alloc] initWithAssetKey:kAssetKey + adDisplayContainer:self.adDisplayContainer + videoDisplay:self.videoDisplay + userContext:nil]; + } else { + streamRequest = [[IMAVODStreamRequest alloc] initWithContentSourceID:kContentSourceID + videoID:kVideoID + adDisplayContainer:self.adDisplayContainer + videoDisplay:self.videoDisplay + userContext:nil]; + } + + [self.adsLoader requestStreamWithRequest:streamRequest]; } - (void)playBackupStream { NSURL *backupStreamURL = [NSURL URLWithString:kBackupStreamURLString]; - // TODO(b/251453188): Fix unused variable - AVPlayerItem *__unused backupStreamItem = [AVPlayerItem playerItemWithURL:backupStreamURL]; [self.videoDisplay loadStream:backupStreamURL withSubtitles:@[]]; [self.videoDisplay play]; [self startMediaSession]; diff --git a/ObjectiveC/PodservingExample/app/ViewController.m b/ObjectiveC/PodservingExample/app/ViewController.m index accd945..12b1417 100644 --- a/ObjectiveC/PodservingExample/app/ViewController.m +++ b/ObjectiveC/PodservingExample/app/ViewController.m @@ -22,13 +22,13 @@ // Enum for stream request type, below typedef enum {kLiveStream, kVODStream} streamType; -/// Podserving stream request type. Either kLiveStream or kVODStream. +/// Specifies the ad pod stream type; either `StreamType.liveStream` or `StreamType.vodStream`. static streamType const kRequestType = kLiveStream; -/// Podserving stream Network Code. +/// Google Ad Manager network code. static NSString *const kNetworkCode = @""; -/// Podserving custom asset key. For live streams only. +/// Livestream custom asset key. static NSString *const kCustomAssetKey = @""; -/// Podserving VTP API +/// Returns the stream manifest URL from the video technical partner or manifest manipulator. static NSString *(^gCustomVTPParser)(NSString *) = ^(NSString *streamID) { // Insert synchronous code here to retrieve a stream manifest URL from your video tech partner // or manifest manipulation server. @@ -99,26 +99,24 @@ - (void)requestStream { [[IMAAVPlayerVideoDisplay alloc] initWithAVPlayer:self.playerViewController.player]; self.adDisplayContainer = [[IMAAdDisplayContainer alloc] initWithAdContainer:self.adContainerView viewController:self]; + IMAStreamRequest *streamRequest; if (kRequestType == kLiveStream) { // Podserving live stream request. - IMAPodStreamRequest *request = - [[IMAPodStreamRequest alloc] initWithNetworkCode:kNetworkCode - customAssetKey:kCustomAssetKey - adDisplayContainer:self.adDisplayContainer - videoDisplay:self.videoDisplay - pictureInPictureProxy:nil - userContext:nil]; - [self.adsLoader requestStreamWithRequest:request]; + streamRequest = [[IMAPodStreamRequest alloc] initWithNetworkCode:kNetworkCode + customAssetKey:kCustomAssetKey + adDisplayContainer:self.adDisplayContainer + videoDisplay:self.videoDisplay + pictureInPictureProxy:nil + userContext:nil]; } else { // Podserving VOD stream request. - IMAPodVODStreamRequest *request = - [[IMAPodVODStreamRequest alloc] initWithNetworkCode:kNetworkCode - adDisplayContainer:self.adDisplayContainer - videoDisplay:self.videoDisplay - pictureInPictureProxy:nil - userContext:nil]; - [self.adsLoader requestStreamWithRequest:request]; + streamRequest = [[IMAPodVODStreamRequest alloc] initWithNetworkCode:kNetworkCode + adDisplayContainer:self.adDisplayContainer + videoDisplay:self.videoDisplay + pictureInPictureProxy:nil + userContext:nil]; } + [self.adsLoader requestStreamWithRequest:streamRequest]; } - (void)playBackupStream { diff --git a/Swift/BasicExample/app/ViewController.swift b/Swift/BasicExample/app/ViewController.swift index a012dbd..19352cb 100644 --- a/Swift/BasicExample/app/ViewController.swift +++ b/Swift/BasicExample/app/ViewController.swift @@ -17,18 +17,27 @@ import AVFoundation import GoogleInteractiveMediaAds import UIKit +// The main view controller for the sample app. class ViewController: UIViewController, IMAAdsLoaderDelegate, IMAStreamManagerDelegate, AVPlayerViewControllerDelegate { - // Live stream asset key, VOD content source and video IDs, and backup content URL. + enum StreamType { case liveStream, vodStream } + /// Specifies the ad pod stream type; either `StreamType.liveStream` or `StreamType.vodStream`. + static let requestType = StreamType.liveStream + /// Livestream custom asset key. static let assetKey = "c-rArva4ShKVIAkNfy6HUQ" - static let contentSourceID = "19463" - static let videoID = @"googleio-highlights" - static let backupStreamURLString = - "http://googleimadev-vh.akamaihd.net/i/big_buck_bunny/bbb-,480p,720p,1080p,.mov.csmil/master.m3u8" //NOLINT + /// VOD stream content source ID. + static let contentSourceID = "2548831" + /// VOD stream video ID. + static let videoID = "tears-of-steel" + /// Backup content URL + static let backupStreamURLString = """ + http://googleimadev-vh.akamaihd.net/i/big_buck_bunny/\ + bbb-,480p,720p,1080p,.mov.csmil/master.m3u8 + """ var adsLoader: IMAAdsLoader? var videoDisplay: IMAAVPlayerVideoDisplay! @@ -103,27 +112,27 @@ class ViewController: self.videoDisplay = IMAAVPlayerVideoDisplay(avPlayer: playerViewController.player!) adDisplayContainer = IMAAdDisplayContainer( adContainer: adContainerView, viewController: self) + let streamRequest: IMAStreamRequest + if ViewController.requestType == StreamType.liveStream { + // Live stream request. + streamRequest = IMALiveStreamRequest( + assetKey: ViewController.assetKey, + adDisplayContainer: adDisplayContainer!, + videoDisplay: self.videoDisplay, + pictureInPictureProxy: nil, + userContext: nil) + } else { + // VOD stream request. + streamRequest = IMAVODStreamRequest( + contentSourceID: ViewController.contentSourceID, + videoID: ViewController.videoID, + adDisplayContainer: adDisplayContainer!, + videoDisplay: self.videoDisplay, + pictureInPictureProxy: nil, + userContext: nil) + } - // Create a live stream request. - let request = IMALiveStreamRequest( - assetKey: ViewController.assetKey, - adDisplayContainer: adDisplayContainer!, - videoDisplay: self.videoDisplay, - pictureInPictureProxy: nil, - userContext: nil) - - // Uncomment this block to create a VOD steam request instead. - /* - let request = IMAVODStreamRequest( - contentSourceID: ViewController.contentSourceID, - videoID: ViewController.videoID, - adDisplayContainer: adDisplayContainer!, - videoDisplay: self.videoDisplay, - pictureInPictureProxy: nil, - userContext: nil) - */ - - adsLoader.requestStream(with: request) + adsLoader.requestStream(with: streamRequest) } @objc func contentDidFinishPlaying(_ notification: Notification) { diff --git a/Swift/PodservingExample/app/ViewController.swift b/Swift/PodservingExample/app/ViewController.swift index bb10b81..30510c5 100644 --- a/Swift/PodservingExample/app/ViewController.swift +++ b/Swift/PodservingExample/app/ViewController.swift @@ -24,13 +24,13 @@ class ViewController: AVPlayerViewControllerDelegate { enum StreamType { case liveStream, vodStream } - /// Podserving stream request type. Either `StreamType.liveStream` or `StreamType.vodStream`. + /// Specifies the ad pod stream type; either `StreamType.liveStream` or `StreamType.vodStream`. static let requestType = StreamType.liveStream - /// Podserving stream Network Code. + /// Google Ad Manager network code. static let networkCode = "" - /// Podserving custom asset key. For livestreams only. + /// Livestream custom asset key. static let customAssetKey = "" - /// Podserving VTP API + /// Returns the stream manifest URL from the video technical partner or manifest manipulator. static let customVTPParser = { (streamID: String) -> (String) in // Insert synchronous code here to retrieve a stream manifest URL from your video tech partner // or manifest manipulation server.