Skip to content

Commit

Permalink
standardizes some coding conventions in samples.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 646130365
  • Loading branch information
gschoppe authored and IMA Developer Relations committed Jun 24, 2024
1 parent 1cd601e commit 40b1353
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 67 deletions.
45 changes: 26 additions & 19 deletions ObjectiveC/BasicExample/app/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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];
Expand Down
36 changes: 17 additions & 19 deletions ObjectiveC/PodservingExample/app/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down
59 changes: 34 additions & 25 deletions Swift/BasicExample/app/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions Swift/PodservingExample/app/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 40b1353

Please sign in to comment.