From 9b28babdba4b5545b1c89981ee4ff7a8fc7ed31d Mon Sep 17 00:00:00 2001 From: Greg Schoppe Date: Thu, 27 Jun 2024 07:28:43 -0700 Subject: [PATCH] Adds a basic example for pod serving DAI in Swift. PiperOrigin-RevId: 647310250 --- Swift/VideoStitcherExample/Podfile | 8 + .../project.pbxproj | 368 ++++++++++++++++++ .../xcschemes/VideoStitcherExample.xcscheme | 85 ++++ .../app/AppDelegate.swift | 29 ++ .../AccentColor.colorset/Contents.json | 11 + .../AppIcon.appiconset/Contents.json | 13 + .../app/Assets.xcassets/Contents.json | 6 + Swift/VideoStitcherExample/app/Info.plist | 15 + .../app/ViewController.swift | 214 ++++++++++ .../VideoStitcherExample/app/iPad.storyboard | 59 +++ .../app/iPhone.storyboard | 59 +++ 11 files changed, 867 insertions(+) create mode 100644 Swift/VideoStitcherExample/Podfile create mode 100644 Swift/VideoStitcherExample/VideoStitcherExample.xcodeproj/project.pbxproj create mode 100644 Swift/VideoStitcherExample/VideoStitcherExample.xcodeproj/xcshareddata/xcschemes/VideoStitcherExample.xcscheme create mode 100644 Swift/VideoStitcherExample/app/AppDelegate.swift create mode 100644 Swift/VideoStitcherExample/app/Assets.xcassets/AccentColor.colorset/Contents.json create mode 100644 Swift/VideoStitcherExample/app/Assets.xcassets/AppIcon.appiconset/Contents.json create mode 100644 Swift/VideoStitcherExample/app/Assets.xcassets/Contents.json create mode 100644 Swift/VideoStitcherExample/app/Info.plist create mode 100644 Swift/VideoStitcherExample/app/ViewController.swift create mode 100644 Swift/VideoStitcherExample/app/iPad.storyboard create mode 100644 Swift/VideoStitcherExample/app/iPhone.storyboard diff --git a/Swift/VideoStitcherExample/Podfile b/Swift/VideoStitcherExample/Podfile new file mode 100644 index 0000000..76a407b --- /dev/null +++ b/Swift/VideoStitcherExample/Podfile @@ -0,0 +1,8 @@ +source 'https://github.com/CocoaPods/Specs.git' + +platform :ios, '17' +project 'VideoStitcherExample.xcodeproj' + +target 'VideoStitcherExample' do + pod 'GoogleAds-IMA-iOS-SDK' +end \ No newline at end of file diff --git a/Swift/VideoStitcherExample/VideoStitcherExample.xcodeproj/project.pbxproj b/Swift/VideoStitcherExample/VideoStitcherExample.xcodeproj/project.pbxproj new file mode 100644 index 0000000..f00cbec --- /dev/null +++ b/Swift/VideoStitcherExample/VideoStitcherExample.xcodeproj/project.pbxproj @@ -0,0 +1,368 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 56; + objects = { + +/* Begin PBXBuildFile section */ + D20D1DC82C1652260021D157 /* iPhone.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D20D1DC62C1652260021D157 /* iPhone.storyboard */; }; + D20D1DC92C1652260021D157 /* iPad.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D20D1DC72C1652260021D157 /* iPad.storyboard */; }; + D21627942C165053004B08EF /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D21627932C165053004B08EF /* AppDelegate.swift */; }; + D21627982C165053004B08EF /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D21627972C165053004B08EF /* ViewController.swift */; }; + D21627A02C165055004B08EF /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D216279F2C165055004B08EF /* Assets.xcassets */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + D20D1DC62C1652260021D157 /* iPhone.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = iPhone.storyboard; sourceTree = ""; }; + D20D1DC72C1652260021D157 /* iPad.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = iPad.storyboard; sourceTree = ""; }; + D21627902C165053004B08EF /* VideoStitcherExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = VideoStitcherExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; + D21627932C165053004B08EF /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + D21627972C165053004B08EF /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; + D216279F2C165055004B08EF /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + D21627A42C165055004B08EF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + D216278D2C165053004B08EF /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + C3F09BE363D05255D29BD1ED /* Pods */ = { + isa = PBXGroup; + children = ( + ); + path = Pods; + sourceTree = ""; + }; + D21627872C165053004B08EF = { + isa = PBXGroup; + children = ( + D21627922C165053004B08EF /* VideoStitcherExample */, + D21627912C165053004B08EF /* Products */, + C3F09BE363D05255D29BD1ED /* Pods */, + ); + sourceTree = ""; + }; + D21627912C165053004B08EF /* Products */ = { + isa = PBXGroup; + children = ( + D21627902C165053004B08EF /* VideoStitcherExample.app */, + ); + name = Products; + sourceTree = ""; + }; + D21627922C165053004B08EF /* VideoStitcherExample */ = { + isa = PBXGroup; + children = ( + D21627932C165053004B08EF /* AppDelegate.swift */, + D21627972C165053004B08EF /* ViewController.swift */, + D216279F2C165055004B08EF /* Assets.xcassets */, + D20D1DC72C1652260021D157 /* iPad.storyboard */, + D20D1DC62C1652260021D157 /* iPhone.storyboard */, + D21627A42C165055004B08EF /* Info.plist */, + ); + name = VideoStitcherExample; + path = app; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + D216278F2C165053004B08EF /* VideoStitcherExample */ = { + isa = PBXNativeTarget; + buildConfigurationList = D21627A72C165055004B08EF /* Build configuration list for PBXNativeTarget "VideoStitcherExample" */; + buildPhases = ( + D216278C2C165053004B08EF /* Sources */, + D216278D2C165053004B08EF /* Frameworks */, + D216278E2C165053004B08EF /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = VideoStitcherExample; + productName = VideoStitcherExample; + productReference = D21627902C165053004B08EF /* VideoStitcherExample.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + D21627882C165053004B08EF /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = 1; + LastSwiftUpdateCheck = 1530; + LastUpgradeCheck = 1530; + TargetAttributes = { + D216278F2C165053004B08EF = { + CreatedOnToolsVersion = 15.3; + }; + }; + }; + buildConfigurationList = D216278B2C165053004B08EF /* Build configuration list for PBXProject "VideoStitcherExample" */; + compatibilityVersion = "Xcode 14.0"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = D21627872C165053004B08EF; + productRefGroup = D21627912C165053004B08EF /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + D216278F2C165053004B08EF /* VideoStitcherExample */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + D216278E2C165053004B08EF /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + D21627A02C165055004B08EF /* Assets.xcassets in Resources */, + D20D1DC92C1652260021D157 /* iPad.storyboard in Resources */, + D20D1DC82C1652260021D157 /* iPhone.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + D216278C2C165053004B08EF /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + D21627982C165053004B08EF /* ViewController.swift in Sources */, + D21627942C165053004B08EF /* AppDelegate.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + D21627A52C165055004B08EF /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + ENABLE_USER_SCRIPT_SANDBOXING = NO; + GCC_C_LANGUAGE_STANDARD = gnu17; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 17.4; + LOCALIZATION_PREFERS_STRING_CATALOGS = YES; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + D21627A62C165055004B08EF /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_USER_SCRIPT_SANDBOXING = NO; + GCC_C_LANGUAGE_STANDARD = gnu17; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 17.4; + LOCALIZATION_PREFERS_STRING_CATALOGS = YES; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + D21627A82C165055004B08EF /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_TEAM = Z95L3YYF93; + ENABLE_USER_SCRIPT_SANDBOXING = NO; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_FILE = app/Info.plist; + INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; + INFOPLIST_KEY_UILaunchStoryboardName = iPhone.storyboard; + INFOPLIST_KEY_UIMainStoryboardFile = iPhone; + INFOPLIST_KEY_UIRequiredDeviceCapabilities = arm64; + INFOPLIST_KEY_UISupportedInterfaceOrientations = UIInterfaceOrientationPortrait; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = google.VideoStitcherExample; + PRODUCT_NAME = "$(TARGET_NAME)"; + SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; + SUPPORTS_MACCATALYST = NO; + SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; + SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + D21627A92C165055004B08EF /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_TEAM = Z95L3YYF93; + ENABLE_USER_SCRIPT_SANDBOXING = NO; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_FILE = app/Info.plist; + INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; + INFOPLIST_KEY_UILaunchStoryboardName = iPhone.storyboard; + INFOPLIST_KEY_UIMainStoryboardFile = iPhone; + INFOPLIST_KEY_UIRequiredDeviceCapabilities = arm64; + INFOPLIST_KEY_UISupportedInterfaceOrientations = UIInterfaceOrientationPortrait; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = google.VideoStitcherExample; + PRODUCT_NAME = "$(TARGET_NAME)"; + SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; + SUPPORTS_MACCATALYST = NO; + SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; + SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + D216278B2C165053004B08EF /* Build configuration list for PBXProject "VideoStitcherExample" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + D21627A52C165055004B08EF /* Debug */, + D21627A62C165055004B08EF /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + D21627A72C165055004B08EF /* Build configuration list for PBXNativeTarget "VideoStitcherExample" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + D21627A82C165055004B08EF /* Debug */, + D21627A92C165055004B08EF /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = D21627882C165053004B08EF /* Project object */; +} diff --git a/Swift/VideoStitcherExample/VideoStitcherExample.xcodeproj/xcshareddata/xcschemes/VideoStitcherExample.xcscheme b/Swift/VideoStitcherExample/VideoStitcherExample.xcodeproj/xcshareddata/xcschemes/VideoStitcherExample.xcscheme new file mode 100644 index 0000000..27ea7f9 --- /dev/null +++ b/Swift/VideoStitcherExample/VideoStitcherExample.xcodeproj/xcshareddata/xcschemes/VideoStitcherExample.xcscheme @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Swift/VideoStitcherExample/app/AppDelegate.swift b/Swift/VideoStitcherExample/app/AppDelegate.swift new file mode 100644 index 0000000..126585f --- /dev/null +++ b/Swift/VideoStitcherExample/app/AppDelegate.swift @@ -0,0 +1,29 @@ +// Copyright 2024 Google LLC. All rights reserved. +// +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software distributed under +// the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF +// ANY KIND, either express or implied. See the License for the specific language governing +// permissions and limitations under the License. + +import CoreData +import UIKit + +@main class AppDelegate: UIResponder, UIApplicationDelegate { + + var window: UIWindow? + + func application( + _ application: UIApplication, + didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? + ) -> Bool { + // Override point for customization after application launch. + return true + } + +} diff --git a/Swift/VideoStitcherExample/app/Assets.xcassets/AccentColor.colorset/Contents.json b/Swift/VideoStitcherExample/app/Assets.xcassets/AccentColor.colorset/Contents.json new file mode 100644 index 0000000..eb87897 --- /dev/null +++ b/Swift/VideoStitcherExample/app/Assets.xcassets/AccentColor.colorset/Contents.json @@ -0,0 +1,11 @@ +{ + "colors" : [ + { + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Swift/VideoStitcherExample/app/Assets.xcassets/AppIcon.appiconset/Contents.json b/Swift/VideoStitcherExample/app/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..13613e3 --- /dev/null +++ b/Swift/VideoStitcherExample/app/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,13 @@ +{ + "images" : [ + { + "idiom" : "universal", + "platform" : "ios", + "size" : "1024x1024" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Swift/VideoStitcherExample/app/Assets.xcassets/Contents.json b/Swift/VideoStitcherExample/app/Assets.xcassets/Contents.json new file mode 100644 index 0000000..73c0059 --- /dev/null +++ b/Swift/VideoStitcherExample/app/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Swift/VideoStitcherExample/app/Info.plist b/Swift/VideoStitcherExample/app/Info.plist new file mode 100644 index 0000000..5ff527f --- /dev/null +++ b/Swift/VideoStitcherExample/app/Info.plist @@ -0,0 +1,15 @@ + + + + + NSAppTransportSecurity + + NSAllowsArbitraryLoads + + + UIMainStoryboardFile~ipad + iPad + UIMainStoryboardFile~iphone + iPhone + + diff --git a/Swift/VideoStitcherExample/app/ViewController.swift b/Swift/VideoStitcherExample/app/ViewController.swift new file mode 100644 index 0000000..25c53eb --- /dev/null +++ b/Swift/VideoStitcherExample/app/ViewController.swift @@ -0,0 +1,214 @@ +// Copyright 2024 Google LLC. All rights reserved. +// +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software distributed under +// the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF +// ANY KIND, either express or implied. See the License for the specific language governing +// permissions and limitations under the License. + +import AVFoundation +import GoogleInteractiveMediaAds +import UIKit + +class ViewController: UIViewController, IMAAdsLoaderDelegate, IMAStreamManagerDelegate { + enum StreamType { case liveStream, vodStream } + + /// Video Stitcher stream request type. + /// + /// Either `StreamType.liveStream` or `StreamType.vodStream`. + static let requestType = StreamType.liveStream + + /// The live stream event ID associated with this stream in your Google Cloud project. + static let liveStreamEventID = "" + /// The custom asset key associated with this stream in your Google Cloud project. + static let customAssetKey = "" + + /// The VOD config ID associated with this stream in your Google Cloud project. + static let vodConfigID = "" + + /// The network code of the Google Cloud account containing the Video Stitcher API project. + static let networkCode = "" + /// The project number associated with your Video Stitcher API project. + static let projectNumber = "" + /// The Google Cloud region where your Video Stitcher API project is located. + static let location = "" + /// A recently generated OAuth Token for a Google Cloud service worker account with the Video + /// Stitcher API enabled. + static let oAuthToken = "" + + /// Backup content URL + static let backupStreamURLString = """ + http://googleimadev-vh.akamaihd.net/i/big_buck_bunny/\ + bbb-,480p,720p,1080p,.mov.csmil/master.m3u8 + """ + + private var adsLoader: IMAAdsLoader? + private var videoDisplay: IMAAVPlayerVideoDisplay! + private var adDisplayContainer: IMAAdDisplayContainer? + private var streamManager: IMAStreamManager? + private var contentPlayhead: IMAAVPlayerContentPlayhead? + private var playerViewController: AVPlayerViewController! + private var adBreakActive = false + + private var contentPlayer: AVPlayer? + @IBOutlet private weak var playButton: UIButton! + @IBOutlet private weak var videoView: UIView! + + override func viewDidLoad() { + super.viewDidLoad() + + playButton.layer.zPosition = CGFloat(MAXFLOAT) + + setupAdsLoader() + setUpPlayer() + } + + @IBAction func onPlayButtonTouch(_ sender: Any) { + requestStream() + playButton.isHidden = true + } + + // MARK: Content Player Setup + + func setUpPlayer() { + // Load AVPlayer with path to our content. + contentPlayer = AVPlayer() + + // Create a player layer for the player. + let playerLayer = AVPlayerLayer(player: contentPlayer) + + // Size, position, and display the AVPlayer. + playerLayer.frame = videoView.layer.bounds + videoView.layer.addSublayer(playerLayer) + } + + // MARK: SDK Setup + + func setupAdsLoader() { + adsLoader = IMAAdsLoader(settings: nil) + adsLoader?.delegate = self + } + + func requestStream() { + // Create an ad display container for ad rendering. + adDisplayContainer = IMAAdDisplayContainer( + adContainer: videoView, + viewController: self, + companionSlots: nil) + // Create an IMAAVPlayerVideoDisplay to give the SDK access to your video player. + let imaVideoDisplay = IMAAVPlayerVideoDisplay(avPlayer: contentPlayer!) + let streamRequest: IMAStreamRequest + if ViewController.requestType == StreamType.liveStream { + // Create a Livestream request. + streamRequest = IMAVideoStitcherLiveStreamRequest( + liveStreamEventID: ViewController.liveStreamEventID, + region: ViewController.location, + projectNumber: ViewController.projectNumber, + oAuthToken: ViewController.oAuthToken, + networkCode: ViewController.networkCode, + customAssetKey: ViewController.customAssetKey, + adDisplayContainer: adDisplayContainer!, + videoDisplay: imaVideoDisplay, + userContext: nil, + videoStitcherSessionOptions: nil) + } else { + // Create a VOD stream request. + streamRequest = IMAVideoStitcherVODStreamRequest( + vodConfigID: ViewController.vodConfigID, + region: ViewController.location, + projectNumber: ViewController.projectNumber, + oAuthToken: ViewController.oAuthToken, + networkCode: ViewController.networkCode, + adDisplayContainer: adDisplayContainer!, + videoDisplay: imaVideoDisplay, + userContext: nil, + videoStitcherSessionOptions: nil) + } + adsLoader?.requestStream(with: streamRequest) + } + + func startMediaSession() { + try? AVAudioSession.sharedInstance().setActive(true, options: []) + try? AVAudioSession.sharedInstance().setCategory(.playback) + } + + // MARK: - IMAAdsLoaderDelegate + + func adsLoader(_ loader: IMAAdsLoader, adsLoadedWith adsLoadedData: IMAAdsLoadedData) { + streamManager = adsLoadedData.streamManager! + streamManager!.delegate = self + streamManager!.initialize(with: nil) + } + + func adsLoader(_ loader: IMAAdsLoader, failedWith adErrorData: IMAAdLoadingErrorData) { + print("Error loading ads: \(String(describing: adErrorData.adError.message))") + let streamURL = URL(string: ViewController.backupStreamURLString) + videoDisplay.loadStream(streamURL!, withSubtitles: []) + videoDisplay.play() + playerViewController.player?.play() + } + + // MARK: - IMAStreamManagerDelegate + func streamManager(_ streamManager: IMAStreamManager, didReceive event: IMAAdEvent) { + print("StreamManager event \(event.typeString).") + switch event.type { + case IMAAdEventType.STREAM_STARTED: + self.startMediaSession() + case IMAAdEventType.STARTED: + // Log extended data. + if let ad = event.ad { + let extendedAdPodInfo = String( + format: "Showing ad %zd/%zd, bumper: %@, title: %@, " + + "description: %@, contentType:%@, pod index: %zd, " + + "time offset: %lf, max duration: %lf.", + ad.adPodInfo.adPosition, + ad.adPodInfo.totalAds, + ad.adPodInfo.isBumper ? "YES" : "NO", + ad.adTitle, + ad.adDescription, + ad.contentType, + ad.adPodInfo.podIndex, + ad.adPodInfo.timeOffset, + ad.adPodInfo.maxDuration) + + print("\(extendedAdPodInfo)") + } + break + case IMAAdEventType.AD_BREAK_STARTED: + // Trigger an update to send focus to the ad display container. + adBreakActive = true + break + case IMAAdEventType.AD_BREAK_ENDED: + // Trigger an update to send focus to the content player. + adBreakActive = false + break + case IMAAdEventType.ICON_FALLBACK_IMAGE_CLOSED: + // Resume playback after the user has closed the dialog. + self.videoDisplay.play() + break + default: + break + } + } + + func streamManager(_ streamManager: IMAStreamManager, didReceive error: IMAAdError) { + print("StreamManager error: \(error.message ?? "Unknown Error")") + } + + // MARK: - AVPlayerViewControllerDelegate + func playerViewController( + _ playerViewController: AVPlayerViewController, + timeToSeekAfterUserNavigatedFrom oldTime: CMTime, + to targetTime: CMTime + ) -> CMTime { + if adBreakActive { + return oldTime + } + return targetTime + } +} diff --git a/Swift/VideoStitcherExample/app/iPad.storyboard b/Swift/VideoStitcherExample/app/iPad.storyboard new file mode 100644 index 0000000..54010e0 --- /dev/null +++ b/Swift/VideoStitcherExample/app/iPad.storyboard @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Swift/VideoStitcherExample/app/iPhone.storyboard b/Swift/VideoStitcherExample/app/iPhone.storyboard new file mode 100644 index 0000000..b74d458 --- /dev/null +++ b/Swift/VideoStitcherExample/app/iPhone.storyboard @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +