AMP Integration Guide: iOS SDK v3

Document created by Herberth Alvarado Employee on May 3, 2016Last modified by Herberth Alvarado Employee on May 15, 2017
Version 9Show Document
  • View in full screen mode

Maintainers: David Cortes Saenz & Miguel Lopez Valenciano

 

 

Akamai AMP player, is a HLS player for iOS and tvOS. Akamai AMP player can manage different plugins like Chromecast Playback, Akamai Media Analytics, Playback Statistics and Octoshape.

 

Installation

 

Amp Provides different frameworks based on what do you need, for this moment you have:

  • AmpCore: manage basic playback and functions related with playback like ID3tracks, Multilanguage Support, Close Caption Support.
  • AmpUICore: the generic UI, you can extend this framework to create your own skins for your player.
  • AmpMediaAnalytics: Plugin to add Akamai Media Analytics Support.
  • AmpOctoshape: Plugin to add support to Octoshape streams.
  • AmpIMA: Plugin to add support to Google IMA ads.
  • AmpNielsenDCR: plugin to add support to Nielsen DCR.

 

 

Implementing the Core

To initialize the core and use a basic playback, first make sure to implement the PlayerEventObserver protocol on your View Controller.

import UIKit

import AmpCore

class ViewController: UIViewController, PlayerEventObserver {

 

Declare a global variable for the AmpPlayerManager and create the instance on your viewDidLoad function for example.

 

var ampMA:AmpMediaAnalyticsManager!

 

override func viewDidLoad() {

    super.viewDidLoad()

    self.createPlayer()

}

func createPlayer() {

    if self.ampPlayerManager == nil {

      // Instantiate player

      let rect = CGRectMake(10, 40, 360, 250)

      self.ampPlayerManager = AmpPlayerManager(parentView: self.view, playerFrame: rect)

      print("VERSION: \(self.ampPlayer.version)")

      // Register

      self.ampPlayerManager.ampPlayer.registerObserver(self)

      self.ampPlayerManager.enableLogs(true, colored: true)

      self.ampPlayerManager.ampPlayer.handleUrl(url)

     }

}

 

Once the player has been initialized, it will wait until the user press the play button. If you want to implement an autoplay after the hanldeURL you can use the PlayerEventObserver using the function onBufferingStateChanged:

 

func onBufferingStateChanged(ampPlayer: AmpPlayer) {

    if (ampPlayer.bufferingState == BufferingState.Ready) {

      print("BufferingState.Ready")

      ampPlayer.play()

     }

}

 

With this simple steps you are now playing videos with Amp 3.

 

Using Plugins

Our recommendation is to initialize all the plugins before call the method handleUrl, this to make sure all the plugin references are ready to use it in the core.

 

Integrating Akamai Media Analytics

To integrate Akamai Media Analytics first import the AmpMediaAnalytics framework:

 

import UIKit

import AmpCore

import AmpMediaAnalytics

 

class ViewController: UIViewController, PlayerEventObserver {

 

After this you need to create a variable will manage the plugin instance:

 

var ampMA:AmpMediaAnalyticsManager!

var ampPlayerManager: AmpPlayerManager!

 

Now you can create a setup media analytics function and call this function before the handle url on your view did load:

 

func setupAnalytics(amPlayer:AmpPlayer) {

    let analyticsUrl = https://ma1019-r.analytics.edgekey.net/config/beacon-8566.xml

    let customData = [

      "title": "AKaMTitle",

      "category": "AKamCategory",

      "playerId": "AKAM AVPlayer playerId",

      "device": "AKAM AVPlayer device",

      "show": "AKAM AVPlayer$show"

     ]

    self.ampMA = AmpMediaAnalyticsManager(ampPlayer: amPlayer, configUrl: analyticsUrl, customData: customData)

}

 

Call this method on your createPlayer:

 

var ampMA:AmpMediaAnalyticsManager!

 

override func viewDidLoad() {

    super.viewDidLoad()

    self.createPlayer()

}

func createPlayer() {

    if self.ampPlayerManager == nil {

      // Instantiate player

      let rect = CGRectMake(10, 40, 360, 250)

      self.ampPlayerManager = AmpPlayerManager(parentView: self.view, playerFrame: rect)

      setupAnalytics(self.ampPlayerManager.ampPlayer)

      print("VERSION: \(self.ampPlayer.version)")

      // Register

      self.ampPlayerManager.ampPlayer.registerObserver(self)

      self.ampPlayerManager.enableLogs(true, colored: true)

      self.ampPlayerManager.ampPlayer.handleUrl(url)

     }

}

Attachments

    Outcomes