AmpChromecast
Home / AmpChromecast
This module’s goal is to ease the integration of GoogleCast and the Akamai AMP Player for iOS. With just a few steps we can achieve this integration, let’s see how.
Installation
Just import the AmpChromecast.framework into 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.
How to Use
Let’s first import the required frameworks:
import AmpCore
import AmpChromecast
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:
ampPlayer = AmpPlayer(parentView: self.view)
ampPlayer.registerObserver(self)
ampPlayer.setLicense(license)
ampChromecast = AmpChromecastManager(ampPlayer: ampPlayer, parentViewController: self)
ampPlayer.handleUrl(url)
You will also need to send a new object with the media info of the active playback.
let builder = GCKMediaInformationBuilder()
builder.contentID = "https://sample-url/video.m3u8"
builder.streamType = .buffered
builder.contentType = "application/x-mpegURL"
ampChromecast.mediaInfo = builder.build()
For starting the video cast to a Chromecast device, just add you own button and assign it the custom class GCKUICastButton
that way video cast will start the video cast flow automatically.
You will also be able to listen to several events from the AmpChromecastManager
by implementing AmpChromecastObserver
and assigning it to the manager as an observer. The way to achieve this is by using the ampChromecast.registerObserver(observer)
method.
Queue management
The Chromecast queue can also be managed through several methods provided to the user by using the following methods.
Methods | Usage |
---|---|
queueInsert |
Insert new elements in the Chromecast queue. You can also define at which point in the . Note: enable the chromecast autoplay flag if you want the videos to showup after the current one is done. |
queueInsertAndPlay |
Inserts a new element to the queue and sets it as the current playing item. |
queueReorderItems |
Reorders the list of media items in the queue. |
queueItemCount |
Use this to check the number of items in the playback queue. |
queueRemoveItem |
Removes the specified item(s) from the queue. |
queueItem |
Returns the instance of the media item on the specified index or with the provided id |
queueIndex |
Returns the index of the item with the given item ID in the playback queue. Note: This returns-1 if there is no such item in the queue. |
queueNext |
Starts the playback of the next item in the queue. |
queuePrevious |
Starts the playback of the previous item in the queue. |