Datazoom is a high-availability real-time data collection solution. This document summarizes how to integrate the Akamai Adaptive Media Player for iOS/tvOS with the Datazoom platform.
- Login to Datazoom here: https://app.datazoom.io
- Add a Collector as indicated here: How to add a Collector
- Copy the
config key
that was created at the end of the process
Click the icon indicated below to copy the Configuration Key
You will see this message:
Prerequisites
iOS / tvOS version 12.1+
XCode 14.1+ ( Swift 5.7.1+ )
Installation
The preferred way of installing DZCollectorTvOSNative is via the Swift Package Manager.
Dependencies
Datazoom framework for Akamai AmpPlayer has one dependency - AmpCore package.
Depending on the installation type for Datazoom package choose type of installation for AmpCore package.
Using Swift Package Manager
Open/Create a project in XCode
Add Swift Package Dependency - navigate to File → Add Packages
Paste the repository URL: https://gitlab.com/datazoom/apple/libraries-release/apple_akamai
For Rules, select Branch (with branch set to main) and click Add Package.
On the confirmation dialog click Add Package, again.
Check if the library is added to the project
Using CocoaPods
This method is being deprecated. Please contact Datazoom if you must use CocoaPods.
Open the terminal and check if CocoaPods is installed in your machine.
pod --version
If the above command returns no version number, then you'll need to install CocoaPods.
sudo gem install cocoapods
After installation, navigate to the Xcode project directory and create aPodfile configuration file if not present.
pod init
Run the command:
open Podfile
Add the DZAkamai pod in the Podfile
source 'https://gitlab.com/datazoom/pod-specs.git' pod 'DZAkamaiUnified','3.4.0'
Pull and update the latest Cocoapods pod specs
Be sure to close any current Xcode sessions and use `your_project_name.xcworkspace` for this project from now on.
Using XCFramework (manually)
Download DZ_Collector.xcframework.zip file from here, and unpack.
Drag and drop the downloaded frameworks into your Xcode project. Drag the file to the files inspector on the left side of XCode. Make sure you check the box "Copy items" in the popup menu that displays while drag and drop the file.
In the selected XCode target, go to the General tab and scroll down to Frameworks, Libraries and Embedded Content (Embedded Binaries in older XCode versions). Make sure that the framework added in the above step is present. If not present, add the framework by clicking the "+" button available in the same section. Also, make sure that Embed option is set to Embed & Sign.
Usage for Swift Language-based Applications
Import and initialization of framework
Importing the framework using the following command:
import DZ_Collector
Initialize the framework by passing along configurationId (provided by Datazoom)
func initialize(configurationId: String, _ completion: ((Bool,Error?) -> Void)?)
Example:
let configurationId = "<Configuration Id provided by Datazoom>" let collector = DZCollector() collector.initialize(configurationId: configurationId, { success, error in if success == true { // init done } else { if let error = error { // init error } } })
Initialization of player
There are several methods to initialize a player, depending on the platform and customer needs.
In case of iOS platform:
Create and Initialize akamai player with url and player view:
func initPlayer(url: String, playerView: UIView, _ completion: ((String?, AmpPlayer?, Error?) -> Void)?)
Example:
collector.initPlayer(url: url, playerView: playerView, { playerId, player, error in if let playerId = playerId, let player = player { // initialization done // playerId - playerContext - useing later to refering player // player - AmpPlayer instance } else { // error - error during initialization } })
Create and Initialize akamai player with url, player view and send player custom metadata:
func initPlayer(url: String, playerView: UIView, metadata: [String : Any]?, _ completion: ((String?, AmpPlayer?, Error?) -> Void)?)
Example:
let playerMetadata: [String: Any]? = ["custom_player_metadata": "metadata"] collector.initPlayer(url: videoUrl, playerView: playerContainerView, metadata: playerMetadata, { playerId, player, error in if let playerId = playerId, let player = player { // initialization done // playerId - playerContext - useing later to refering player // player - AmpPlayer instance } else { // error - error during initialization } })
In case of tvOS platform:
Create and Initialize akamai player with url, parent controller, player controller and player view:
func initPlayer(url: String, parentViewController: UIViewController, playerController: AVPlayerViewController, playerView: UIView, _ completion: ((String?, AmpCore.AmpPlayer? ,Error?) -> Void)?)
Example:
collector.initPlayer(url: url, parentViewController: parentVC, playerController: controller, playerView: playerView, { playerId, player, error in if let playerId = playerId, let player = player { // initialization done // playerId - playerContext - useing later to refering player // player - AmpPlayer instance } else { // error - error during initialization } })
Create and Initialize akamai player with url, parent controller, player controller, player view and send player custom metadata:
func initPlayer(url: String, parentViewController: UIViewController, playerController: AVPlayerViewController, playerView: UIView, metadata: [String:Any]?, _ completion: ((String?, AmpCore.AmpPlayer?, Error?) -> Void)?)
Example:
let playerMetadata: [String: Any]? = ["custom_player_metadata": "metadata"] collector.initPlayer(url: videoUrl, parentViewController: parentVC, playerController: controller, playerView: playerView, metadata: playerMetadata, { playerId, player, error in if let playerId = playerId, let player = player { // initialization done // playerId - playerContext - useing later to refering player // player - AmpPlayer instance } else { // error - error during initialization } })
Common methods for both (iOS/tvOS) platform:
Initialize with already created akamai player:
func initPlayer(player: AmpCore.AmpPlayer, _ completion: ((String?, Error?) -> Void)?)
Example:
collector.initPlayer(player: player, { playerId, error in if let playerId = playerId { // initialization done // playerId - playerContext - useing later to refering player } else { // error - error during initialization } })
Initialize with already created akamai player and send player custom metadata:
func initPlayer(player: AmpCore.AmpPlayer, metadata: [String : Any]?, _ completion: ((String?, Error?) -> Void)?)
Example:
let playerMetadata: [String: Any]? = ["custom_player_metadata": "metadata"] collector.initPlayer(player: player, metadata: playerMetadata, { playerId, error in if let playerId = playerId { // initialization done // playerId - playerContext - useing later to refering player // player - AmpPlayer instance } else { // error - error during initialization } })
Deinitialization of player
func deinitPlayer(playerContext: String,_ completion: ((Bool, Error?) -> Void)?)
Example:
collector.deinitialize(playerContext: playerContext, { success, error in if success == true { // player deinit done } else { if let error = error { // player deinit error } } })
Deinitialization of framework
func deinitialize()
Example:
collector.deinitialize()
Usage of Google IMA Ads
Download Client-Side SDK from:
Add the framework
Import the framework
Add default implementation by adding IMAAdEventExtension.swift and DZAdDataIMA.swift files
Add In code (suggested implementation)
func initAds(adUrl: String, controller: AVPlayerController, playerContext: String, contentDuration: Float = 0, _ completion: ((Bool, Error?) -> Void)?) { let ad: DZAdDataIMA = DZAdDataIMA(playerContext: playerContext) ad.delegate = self ad.requestAds(url: adUrl, controller: controller, contentDuration: contentDuration) completion?(true, nil) }
Comments
0 comments
Please sign in to leave a comment.