Skip to content

Commit 731c1b0

Browse files
Thang DuongIMA Developer Relations
authored andcommitted
Renames videoView to adUIView for clarity.
This CL also includes minor changes: - Re-format Copyright message. - Update storyboard files to horizontally center align the UI elements. - Set stream parameters using sample values from https://developers.google.com/ad-manager/dynamic-ad-insertion/streams. PiperOrigin-RevId: 803604872
1 parent ed0e9fd commit 731c1b0

File tree

4 files changed

+54
-44
lines changed

4 files changed

+54
-44
lines changed

Swift/SGAIClientSideExample/app/AppDelegate.swift

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
// Copyright 2025 Google LLC. All rights reserved.
1+
// Copyright 2025 Google LLC
22
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
36
//
4-
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
5-
// file except in compliance with the License. You may obtain a copy of the License at
7+
// https://www.apache.org/licenses/LICENSE-2.0
68
//
7-
// http://www.apache.org/licenses/LICENSE-2.0
8-
//
9-
// Unless required by applicable law or agreed to in writing, software distributed under
10-
// the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11-
// ANY KIND, either express or implied. See the License for the specific language governing
12-
// permissions and limitations under the License.
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
1314

1415
import CoreData
1516
import UIKit

Swift/SGAIClientSideExample/app/ViewController.swift

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
// Copyright 2025 Google LLC. All rights reserved.
1+
// Copyright 2025 Google LLC
22
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
36
//
4-
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
5-
// file except in compliance with the License. You may obtain a copy of the License at
7+
// https://www.apache.org/licenses/LICENSE-2.0
68
//
7-
// http://www.apache.org/licenses/LICENSE-2.0
8-
//
9-
// Unless required by applicable law or agreed to in writing, software distributed under
10-
// the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11-
// ANY KIND, either express or implied. See the License for the specific language governing
12-
// permissions and limitations under the License.
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
1314

1415
import AVFoundation
1516
import GoogleInteractiveMediaAds
@@ -21,33 +22,43 @@ class ViewController:
2122
{
2223

2324
private enum StreamParameters {
24-
static let contentStream = "[YOUR_LIVE_STREAM_URL]"
25+
static let contentStream =
26+
"https://devstreaming-cdn.apple.com/videos/streaming/examples/bipbop_16x9/bipbop_16x9_variant.m3u8"
27+
2528
// Find your [Google Ad Manager network code](https://support.google.com/admanager/answer/7674889)
2629
// or use the test network code and custom asset key with the DAI type "Pod serving manifest"
2730
// from [DAI sample streams](https://developers.google.com/ad-manager/dynamic-ad-insertion/streams#pod_serving_dai).
28-
static let networkCode = "[YOUR_GOOGLE_AD_MANAGER_NETWORK_CODE]"
29-
static let customAssetKey = "[YOUR_GOOGLE_DAI_CUSTOM_ASSET_KEY]"
31+
32+
/// Google Ad Manager network code.
33+
static let networkCode = "21775744923"
34+
35+
/// Google DAI livestream custom asset key.
36+
static let customAssetKey = "sgai-hls-live"
37+
3038
// Set your ad break duration.
3139
static let adBreakDurationMs = 10000
3240
}
3341

34-
/// The AVPlayer instance that plays the content and the ads.
35-
private var player: AVPlayer!
36-
3742
/// The play button to start the stream.
3843
/// It is hidden when the stream starts playing.
3944
@IBOutlet private weak var playButton: UIButton!
40-
@IBOutlet private weak var videoView: UIView!
4145

42-
/// The entry point of the IMA SDK to make stream requests to Google Ad Manager.
43-
private var adsLoader: IMAAdsLoader!
46+
/// The view to display the ad UI elements: countdown, skip button, etc.
47+
/// It is hidden when the stream starts playing.
48+
@IBOutlet private weak var adUIView: UIView!
4449

45-
/// The reference of your video view for the IMA SDK to create the ad's user interface elements.
50+
/// The reference of your ad UI view for the IMA SDK to create the ad's user interface elements.
4651
private var adDisplayContainer: IMAAdDisplayContainer!
4752

53+
/// The AVPlayer instance that plays the content and the ads.
54+
private var player: AVPlayer!
55+
4856
/// The reference of your video player for the IMA SDK to play and monitor the ad breaks.
4957
private var videoDisplay: IMAAVPlayerVideoDisplay!
5058

59+
/// The entry point of the IMA SDK to make stream requests to Google Ad Manager.
60+
private var adsLoader: IMAAdsLoader!
61+
5162
/// The reference of the ad stream manager, set when the ad stream is loaded.
5263
/// The IMA SDK requires a strong reference to the stream manager for the entire duration of
5364
/// the ad break.
@@ -60,15 +71,13 @@ class ViewController:
6071

6172
// Initialize the IMA SDK.
6273
let adLoaderSettings = IMASettings()
63-
// Uncomment the next line for ad UI localization.
64-
// adLoaderSettings.language = "es"
6574
adsLoader = IMAAdsLoader(settings: adLoaderSettings)
6675

6776
// Set up the video player and the container view.
6877
player = AVPlayer()
6978
let playerLayer = AVPlayerLayer(player: player)
70-
playerLayer.frame = videoView.bounds
71-
videoView.layer.addSublayer(playerLayer)
79+
playerLayer.frame = adUIView.bounds
80+
adUIView.layer.addSublayer(playerLayer)
7281
playButton.layer.zPosition = CGFloat.greatestFiniteMagnitude
7382

7483
// Create an object to monitor the stream playback.
@@ -79,7 +88,7 @@ class ViewController:
7988
// Create a container object for ad UI elements.
8089
// See [example in video ads](https://support.google.com/admanager/answer/2695279#zippy=%2Cexample-in-video-ads)
8190
adDisplayContainer = IMAAdDisplayContainer(
82-
adContainer: videoView, viewController: self, companionSlots: nil)
91+
adContainer: adUIView, viewController: self, companionSlots: nil)
8392

8493
// Specify the delegate for hanlding ad events of the stream session.
8594
adsLoader.delegate = self

Swift/SGAIClientSideExample/app/iPad.storyboard

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@
1616
</layoutGuides>
1717
<view key="view" contentMode="scaleToFill" id="Bhd-Z9-jHM">
1818
<rect key="frame" x="0.0" y="0.0" width="820" height="1180"/>
19-
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
19+
<autoresizingMask key="autoresizingMask" flexibleMaxY="YES"/>
2020
<subviews>
2121
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="SGAI Client-side Example" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="7z2-AB-Rcf" userLabel="SGAI Client-side Example">
22-
<rect key="frame" x="20" y="116" width="780" height="62"/>
23-
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
22+
<rect key="frame" x="19.31478537360681" y="115.99999999998045" width="780" height="61.999999999973397"/>
23+
<autoresizingMask key="autoresizingMask" flexibleMaxY="YES"/>
2424
<fontDescription key="fontDescription" type="system" pointSize="37"/>
2525
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
2626
<nil key="highlightedColor"/>
2727
</label>
2828
<view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="QRR-Z0-TkP">
29-
<rect key="frame" x="90" y="289" width="640" height="360"/>
30-
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
29+
<rect key="frame" x="89.616852146253905" y="288.99999999995089" width="639.9999999998447" height="360.00000000000023"/>
30+
<autoresizingMask key="autoresizingMask" flexibleMaxY="YES"/>
3131
<subviews>
3232
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="eRN-Vg-Dqv">
3333
<rect key="frame" x="245" y="84" width="150" height="191"/>
@@ -47,8 +47,8 @@
4747
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
4848
</view>
4949
<connections>
50+
<outlet property="adUIView" destination="QRR-Z0-TkP" id="dQk-gF-We8"/>
5051
<outlet property="playButton" destination="eRN-Vg-Dqv" id="aVm-Iq-3yY"/>
51-
<outlet property="videoView" destination="QRR-Z0-TkP" id="6ql-Zv-hmA"/>
5252
</connections>
5353
</viewController>
5454
<placeholder placeholderIdentifier="IBFirstResponder" id="2FX-P4-3e8" userLabel="First Responder" sceneMemberID="firstResponder"/>

Swift/SGAIClientSideExample/app/iPhone.storyboard

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
2020
<subviews>
2121
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="SGAI Client-side Example" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="9bH-14-R52" userLabel="SGAI Client-side Example">
22-
<rect key="frame" x="16" y="70" width="361" height="21"/>
23-
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
22+
<rect key="frame" x="13.48852040816746" y="69.999999999998863" width="361.00000000010596" height="20.999999999993861"/>
23+
<autoresizingMask key="autoresizingMask" flexibleMaxY="YES"/>
2424
<fontDescription key="fontDescription" type="system" pointSize="17"/>
2525
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
2626
<nil key="highlightedColor"/>
2727
</label>
2828
<view contentMode="scaleAspectFit" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="uHt-ZA-PWM">
29-
<rect key="frame" x="36" y="125" width="320" height="180"/>
30-
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
29+
<rect key="frame" x="34.161989795928548" y="124.99999999999795" width="320.00000000009413" height="180.00000000000023"/>
30+
<autoresizingMask key="autoresizingMask" flexibleMaxY="YES"/>
3131
<subviews>
3232
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="pkY-3B-bnC">
3333
<rect key="frame" x="123" y="39" width="75" height="102"/>
@@ -47,8 +47,8 @@
4747
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
4848
</view>
4949
<connections>
50+
<outlet property="adUIView" destination="uHt-ZA-PWM" id="Hhd-ik-X5b"/>
5051
<outlet property="playButton" destination="pkY-3B-bnC" id="eFF-Bg-buW"/>
51-
<outlet property="videoView" destination="uHt-ZA-PWM" id="Dyr-TX-Sn1"/>
5252
</connections>
5353
</viewController>
5454
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>

0 commit comments

Comments
 (0)