Akamai AMP Player for tvOS

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. This guide will cover the tvOS process.

Installation

To install the AMP Player on you project you only need to import the main framework:

  • AmpCoreTV.framework

*Note: Make sure to add the frameworks as Embedded Binaries or you’ll get an error about a missing image. *

How to Use

Using AMP player on your tvOS project is very simple, you need to first to declare two variables of type AmpPlayer and AVPlayerViewController:

    var ampPlayer: AmpPlayer!
    var playerController: AVPlayerViewController = AVPlayerViewController()

In tvOS we don’t provide a custom UI, since the default one provides so much features, such as the image preview when you are seeking, and we also believe it to be pretty as is.

      override func viewDidLoad() {
        super.viewDidLoad()

        self.playVideo(url, playerController: self.playerController)
    }

    public func playVideo(videoUrl: String, playerController: AVPlayerViewController) {

        self.ampPlayer = AmpPlayer()

        print("Amp Version: \(self.ampPlayer.version)")

        self.setupPlayerController(playerController)

        // Register as an observer if you implemented PlayerEventObserver and need to listen to AMP-related events
        self.ampPlayer.registerObserver(self)

        self.ampPlayer.autoplay = true

        self.ampPlayer.handleUrl(videoUrl)

        // If you want to be notified when certain seconds have been reached
        let times = [2.0, 4.0, 6.0, 8.0]
        _ = CuepointManager(ampPlayer: self.ampPlayer, observer: self, times: times)

    }

    func setupPlayerController(playerController: AVPlayerViewController) {
        self.playerController = playerController

        self.playerController.delegate = self
        self.playerController.player = self.ampPlayer.player
        self.playerController.view.frame = self.view.frame
        self.addChildViewController(self.playerController)
        self.view.addSubview(self.playerController.view)
    }

This will create a player using the AVPlayerViewController’s main view as our player view, we also set ampPlayer.autoplay to true, this way you don’t have to use our event system unless you need to.

AMP Player also offers custom callbacks to manage the Playback events and plugin events.

For example if you want to track the Playback events, you need to implement the PlayerEventObserver and register to the manager.

class ViewController: UIViewController, PlayerEventObserver

Now register the the observer on the AmpPlayerManager using the AmpPlayer reference

self.ampPlayer.registerObserver(self)

Finally you can implement the callbacks on your class, we are listeng here when the stream is ready to play, to generate an autoplay feature.

func onAmpBufferingStateChanged(ampPlayer: AmpPlayer) {
  if (ampPlayer.bufferingState == BufferingState.Ready) {
    print("BufferingState.Ready")
    ampPlayer.play()
  }
}

Need help?

If you need help trying to integrate the player on your project, or you want to report issues or problems you can send a email to amp-sdk-support@akamai.com