AMP Core
Akamai Adaptive Media Player is a media player for iOS and tvOS. Akamai AMP can manage different plugins like Chromecast Playback, Akamai Media Analytics, Playback Statistics, Facebook Audience Network, ComScore, and VR.
This is the main module, it takes the AVPlayer and augments its functionality to provide proper event notifications, using a well defined and documented protocol stating what events exist and what they are all about. It also ships with a custom UI
Installation
Import the AmpCore.framework into your project to manage basic playback and its related functions like ID3 Tracks, Multi-Language and Closed Captions support. Note: Make sure to add the frameworks as Embedded Binaries or you’ll get an error about a missing image.
How to Use
To initialize the Core and use basic playback, first import the required frameworks and make sure to implement the PlayerEventObserver protocol on your View Controller
import UIKit
import AmpCore
class ViewController: UIViewController, PlayerEventObserver {
Then, let’s add the AMP Player variable in our UIViewController:
var ampPlayer: AmpPlayer!
And it’s time to instantiate it now in your viewDidLoad function:
override func viewDidLoad() {
super.viewDidLoad()
self.ampPlayer = AmpPlayer(parentView: self.view)
self.ampPlayer.setLicense(license)
self.ampPlayer.registerObserver(self)
self.ampPlayer.play(url: YOUR_VIDEO_URL)
}
The previous initializes the player, sets the license, registers the class as an observer and then starts handling the stream, this will not start your playback, there are a couple of ways you can implement autoplay in our player. The first way is to simply set the autoplay property of the AmpPlayer’s instance to true:
self.ampPlayer.autoplay = true
The other way to accomplish autoplay in our play is to listen to the onBufferingStateChanged and check for the state BufferingState.ready, then you would proceed to call play in your AmpPlayer instance:
func onBufferingStateChanged(_ ampPlayer: AmpPlayer) {
if (ampPlayer.bufferingState == BufferingState.ready) {
// Here we use the manual way to achieve autoplay
ampPlayer.play()
}
}
Setting up the player
The following variables and methods can be used the player set up.
Variables
Variable | Type | Description | Optional |
---|---|---|---|
player |
AVPlayer | The player’s version | Yes |
enableAdUI |
Bool | Delegate to handle the playback actions | No |
version |
String | AVFoundation native player | No |
externalPlaybackDelegate |
ExternalPlaybackDelegate | Flag to allow the player controls during an ad | Yes |
domain |
String | The project’s domain | No |
isAppInBackground |
Bool | Whether or not the app is in background mode | No |
licenseString |
String | License in use | Yes |
nowPlayingInfoCenterEnabled |
Bool | Enable or disable locked screen widget | No |
observable |
Observable | The container in charge of storing, deleting and iterating on the registered observers | Yes |
media |
Media | Manages the media object | Yes |
isDVREnabled |
Bool | Whether or not DVR is enabled | No |
streamType |
StreamType | The stream type | No |
timedMetadata |
[AVMetadataItem] | Metadata at the current time frame (ID3Tags) | No |
streamDownloader |
StreamDownloader | Class in charge of downloading the stream file | No |
playerView |
AmpPlayerView | Player View | Yes |
autoplay |
Bool | Whether or not autoplay is enabled | No |
isAutoRecoveryEnabled |
Bool | Whether or not auto recovery is enabled | No |
streamAutoRecoveryInterval |
Double | Time rate in seconds to verify if the stream is up or not | No |
streamAutoRecoveryText |
String | Stream auto recovery error text | No |
isLiveStream |
Bool | Whether or not the stream is a live stream | No |
dvrStartTime |
Double | Starting point of a DVR stream | No |
playerSpeed |
Float | Sets the player speed in terms of 1x, 2x, 3x, etc | No |
audioTracks |
[String] | List of available audio tracks | No |
closeCaptions |
[String] | List of available closed captions | No |
airplayEnabled |
Bool | Whether or not airplay playback is enabled | No |
chromecastEnabled |
Bool | Whether or not Chromecast playback is enabled | No |
logsEnabled |
Bool | Whether or not logs are enabled | No |
logColoringEnabled |
Bool | Whether or not log coloring is enabled | No |
inlineCustomView |
AmpUIView | Customized view for an inline player instance | Yes |
fullCustomScreenView |
AmpUIView | Customized view for a fullscren player instance | Yes |
parentViewController |
UIViewController | AMP Parent View Controller | Yes |
isFullscreen |
Bool | Whether or not AMP is on fullscreen mode | No |
playerFrame |
CGRect | Player Frame | Yes |
fullscreenFrame |
CGRect | Full Screen Frame | Yes |
isPictureInPictureEnabled |
Bool | Whether or not the player supports Picture in Picture | No |
pictureInPictureDelegate |
AVPictureInPictureControllerDelegate | Picture in Picture Delegate | Yes |
pictureController |
AVPictureInPictureController | Picture in Picture Controller | Yes |
isPictureInPictureSupported |
pictureInPictureDelegate | Whether or not Picture in Picture is supported | Yes |
Methods
Methods | Parameters | Usage |
---|---|---|
destroy |
Destroys the player instance and performs the clean up | |
registerObserver |
observer: PlayerEventObserver | Registers an observer to be notified of player events |
removeObserver |
id: Int | Removes a registered observer |
tap |
Trigger a tap on the player | |
Setters
Methods | Parameters | Usage |
---|---|---|
setLicense |
license: String | Setter for the player license |
play |
url streamUrl: String | Setter for the playback URL as a String |
play |
asset: AVURLAsset | Setter for the AVURLAsset to play |
play |
url:String, certificateUrl: String, serverURL: String, customHeaders: [String:String]? = nil, jsonResponse: Bool = false | Setter for the playback URL using Fairplay DRM |
setEventManager |
url: String, states: [State], verificationTimeSeconds:Int | Setter for the Event Manager with the URL to the text file, the array of States to verify and number of seconds to try again |
setPoster |
url:String, type:PosterImageType default: .poster, mode:UIView.ContentMode? default: nil, parentView:UIView? default: nil | Setter for the image poster with its URL as a String, Optional UIViewContentMode to display the image on view as mode and Optional UIView with Parent View as parentView |
setPoster |
image:UIImage, type:PosterImageType default: .poster, mode:UIView.ContentMode? default: nil, parentView:UIView? default: nil | Setter for the image poster as an UIImage, Optional UIViewContentMode to display the image on view as mode and Optional UIView with Parent View as parentView |
setMaxQualityLevel |
level:QualityLevel | Setter for the quality level of the cuurent stream |
setMediaCharacteristic |
mediaCharacteristic: String, type: MediaCharacteristic | Setter for the media characteristic with its string code and MediaCharacteristic enum |
setMediaInfo |
Setter for the media information metadata | |
setShareButtonVisible |
visible: Bool | Setter for the visibility for the Share Button |
setSpinnerVisibility |
shown: Bool | Setter for the spinner visibility |
setCloseCaption |
url: String, forLanguage: String | Setter for the WebVTT Closed Captions File |
setupFullscreen |
handler: FullscreenHandler?, autoFullscreen: Bool = false | Sets up the fullscreen handling |
Playback
These are the variables and methods used specifically to configure media playback:
Variables
Variable | Type | Description | Optional |
---|---|---|---|
streamInfo |
StreamInfo | The stream’s information | Yes |
allowBackgroundPlayback |
Bool | Enable or disable playback on background | No |
playbackStateOnAppDidBecomeActive |
PlaybackState | Set the playback mode when the player enters to the background | No |
isStreamAutoRecoveryEnabled |
Bool | Enable or disable the stream verification mode. Default is false | No |
url |
String | The current playback URL | Yes |
isAdPlaying |
Bool | Whether or not an ad is playing | No |
isExternalPlayerPlaying |
Bool | Whether or not an external associated player is playing | No |
streamDuration |
Double | Stream duration in seconds | No |
currentTimeWithoutAds |
Double | Current time without server side ads | Yes |
currentTimeWithAds |
Double | Current time with server side ads | No |
totalAdTime |
Double | Total server side ads time combined | No |
prerollAdTime |
Double | Total server side preroll time | No |
hasPostroll |
Bool | Whether or not a postroll exists | No |
playbackState |
PlaybackState | Current status of the video playback | No |
bufferingState |
BufferingState | Current buffering state | No |
isStalled |
Bool | Whether or not the player is stalled | No |
fps |
Float | Current frames per second value | No |
currentStreamTime |
Double | Current time of the stream | No |
dvrLiveTime |
Double | Current time of a DVR stream | No |
Methods
Methods | Parameters | Usage |
---|---|---|
play |
Plays the stream and sets the playbackState to playing | |
pause |
Pauses the stream and sets the playbackState to paused | |
replay |
If the playback ended, plays the same stream from the beginning | |
seekTo |
seconds:TimeInterval | Seeks the stream to the given position in seconds |
seekTo |
date:Date | Seeks the stream to the given date |
goLive |
Seeks the stream to live | |
stop |
Stops the stream and sets the PlaybackState to stopped | |
isPlaybackComplete |
Check if the playback matches the end of the video | |
updatePosition |
Updates the position when an asset is playing | |
changePosition |
Force an update on the playback timebar | |
mute |
Mutes the playback | |
unmute |
Unmutes the playback | |
Visualization
These are the visualization related variables and methods
Variables
Variable | Type | Description | Optional |
---|---|---|---|
title |
String | Title used on default UI | Yes |
subtitle |
String | Subtitle used on default UI | Yes |
overrideDefaultFullscreenBehaviour |
Bool | Flag to override the fullscreen validation to check on the toogle state instead of the size of the player. Don’t override this value unless your implementation of the fullscreen won’t cover the total of the screen, since you could expirience undesired behaviours. | No |
posterImage |
PosterImage | Poster image | Yes |
buttonOverlayEnabled |
Bool | Whether or not the play button overlay is enabled | No |
loadingIndicatorEnabled |
Bool | Whether or not the buffer loading indicator is enabled | No |
Methods
Methods | Parameters | Usage |
---|---|---|
showPosterImage |
type:PosterImageType, default: .poster | Show the poster image |
hidePosterImage |
type:PosterImageType, default: .poster | Hide the poster image |
manageFullScreen |
Toggles to fullscreen visualization of the player | |
toggleCloseCaptions |
sender: AnyObject | Toggles the close captions. Works only on custom views |
manageCloseCaptions |
sender: AnyObject | Shows the pop-up with the available options for closed captions. Works only on custom views |
showPopOver |
popOverController: UIViewController, sender: AnyObject | Opens the pop over for the close captions and audio tracks. The popOverController is the view in which the audio track and close captions wil be displayed. |
managePictureInPicture |
Toggles the Picture in Picture | |
Notifications
These methods handle the notifications on player events
Methods | Parameters | Usage |
---|---|---|
handleWillResignActive |
Notification on player will resign active | |
handleDidBecomeActive |
Notification on player did become active | |
handleAVPlayerAccess |
notification: Notification | Notification on player handle AVPlayer Access with a NSNotification |
playerInfoChanged |
notification: Notification | Manage the information change on playback with the NSNotification |
playerItemDidPlayToEndTime |
notification: Notification | Manage when the player finished to play an asset with the NSNotification |
playerDidStall |
notification: Notification | Manage when the player stalled while playing an asset |
playerItemFailedToPlayToEndTime |
notification: Notification | Manage when the player is unable play an asset to the end time |
handleControlButtonClicked |
Notification on clicking the Control Button | |
newErrorLogEntry |
notification: Notification | Manage general errors |
Miscellaneous
These variables can assist with AMP related tasks
Variables
Variable | Type | Description | Optional |
---|---|---|---|
currentSystemVolume |
Float | Curremt system volume | No |
currentUTCTime |
Double | Current UTC time | Yes |