Chromecast Module for AMP iOS

Our Chromecast module augments our core playback SDK, by managing the connection and synchronization between Chromecast devices and AMP.

Installation

First, import the AmpChromecast.framework in your project. For more information check out the AmpCore’s documentation.

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

Chromecast also has some dependencies, so we must add them as well:

  • MediaPlayer.framework
  • AudioToolbox.framework
  • Accelerate.framework
  • libc++.tbd

Please keep referring to the Chromecast official documentation as their dependencies keep changing.

How to Use

Let’s first import the required frameworks:

import AmpCore
import AmpChromecast
// If you listen to our `AmpChromecastObserver` events, you must import `GoogleCast`
import GoogleCast

Then, let’s add the related variables in our UIViewController:

    var ampPlayer: AmpPlayer!
    var ampChromecast: AmpChromecastManager!

And it’s time to instantiate them now, in your viewDidLoad function:

    // Instantiate player

    self.ampPlayer = AmpPlayer(parentView: self.view)
    self.ampPlayer.autoplay = true
    self.ampPlayer.setLicense(license)

    // Register yourself as an observer if required
    self.ampPlayer.registerObserver(self)

    // Instantiate the Chromecast Manager
    self.ampChromecast = AmpChromecastManager(ampPlayer: self.ampPlayer)
    // If you want to listen to `AmpChromecastObserver` events, register as an observer
    self.ampChromecast.registerObserver(self)

    self.ampPlayer.handleUrl(url)

There is just one more step, which is displaying the list of devices so the user can start streaming to it:

    @IBAction func chromecastButton() {
        self.ampChromecast.showDevicesMenu()
    }

As you probably noticed, it is an IBAction, so you just link that action to the UI element that should display the devices menu, such as a button.

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