Adaptive Media Player

AmpCore Docs

AmpPlayer

@objc open class AmpPlayer: NSObject

Class in charge of augmenting the AVPlayer related functionality.

  • The type of Media Characteristic defined in a enum

    • CloseCaptions: The Characteristic for Close Captions.
    • Audio: The Characteristic for Audio Tracks.
    See more

    Declaration

    Swift

    @objc public enum MediaCharacteristic: Int
  • The native player.

    Declaration

    Swift

    @objc open var player: AVPlayer?
  • The stream’s information

    Declaration

    Swift

    @objc open var streamInfo: StreamInfo?
  • The player’s version

    Declaration

    Swift

    @objc open let version: String = Bundle(for: AmpPlayer.self).infoDictionary!["CFBundleShortVersionString"] as! String
  • The project’s domain

    Declaration

    Swift

    @objc open static let domain: String = "com.media.akamai"
  • Return true or false if the app is on background mode

    Declaration

    Swift

    public var isAppInBackground = false
  • License used

    Declaration

    Swift

    @objc open var licenseString:String?
  • The native player item.

    Declaration

    Swift

    @objc open var playerItem: AVPlayerItem?
  • Enable or disable the playback on the background, on your App you must enable Background modes with Audio, Airplay and Picture in Picture

    Declaration

    Swift

    open var allowBackgroundPlayback:Bool = false
  • Set the playback mode when the player enters to the background

    Declaration

    Swift

    open var playbackStateOnAppDidBecomeActive:PlaybackState = .playing
  • Title used on default UI

    Declaration

    Swift

    @objc open var title: String?
  • The container in charge of storing, deleting and iterating on the registered observers.

    Declaration

    Swift

    open var observable: Observable<PlayerEventObserver>?
  • Return true or false if an ad is playing

    Declaration

    Swift

    open var isAdPlaying:Bool = false
  • Return stream time without ads (Server side ads)

    Declaration

    Swift

    open var timeWithoutAds:Double? = nil
  • Return stream time current without ads (Server side ads)

    Declaration

    Swift

    open var currentTimeWithoutAds:Double? = nil
  • Return stream time with ads (Server side ads)

    Declaration

    Swift

    open var currentTimeWithAds:Double = 0
  • Return total ad time (Server side ads)

    Declaration

    Swift

    open var totalAdTime:Double = 0.0
  • Return preroll ad time (Server side ads)

    Declaration

    Swift

    open var prerollAdTime:Double = 0.0
  • Variable used to manage the json or xml config

    Declaration

    Swift

    open var ampConfig:AmpConfig?
  • Variable used to manage the media loaded from json

    Declaration

    Swift

    @objc open var mediaObject:Media?
  • Custom inline UI

    Declaration

    Swift

    @objc open var inlineCustomView:AmpUIView?
  • Custom fullscren UI

    Declaration

    Swift

    @objc open var fullCustomScreenView:AmpUIView?
  • Enables or disables autoplay

    Declaration

    Swift

    @objc open var autoplay: Bool = false
  • Check if DVR is enabled

    Declaration

    Swift

    @objc open var isDVREnabled:Bool = false
  • url

    The current URL

    Declaration

    Swift

    @objc open var url: String!
  • The type of the stream loaded

    Declaration

    Swift

    @objc open var streamType: StreamType
  • The current state of the video playback

    Declaration

    Swift

    @objc open var playbackState: PlaybackState
  • The current metadata on current time (ID3Tags)

    Declaration

    Swift

    @objc open var timedMetadata:[AVMetadataItem]
  • Return AMP Parent View Controller

    Declaration

    Swift

    @objc public var parentViewController: UIViewController?
  • Return true or false if AMP is on fullscreen mode

    Declaration

    Swift

    @objc open var isFullscreen: Bool
  • Return Player Frame

    Declaration

    Swift

    open var playerFrame: CGRect?
  • Return Full Screen Frame

    Declaration

    Swift

    open var fullscreenFrame: CGRect?
  • Return true or false if the player supports Picture in Picture

    Declaration

    Swift

    @objc dynamic open var isPictureInPictureEnabled:Bool = true
  • Picture in Picture Delegate

    Declaration

    Swift

    open var pictureInPictureDelegate:AVPictureInPictureControllerDelegate?
  • Initializes a new AmpPlayer with the parameters provided.

    Declaration

    Swift

    public override init()

    Return Value

    A configured instance of an AmpPlayer.

  • Notification on player will resign active

    Declaration

    Swift

    @objc open func handleWillResignActive()
  • Notification on player did become active

    Declaration

    Swift

    @objc open func handleDidBecomeActive()
  • Notification on player handle AVPlayer Access.

    Declaration

    Swift

    @objc open func handleAVPlayerAccess(_ notification: Notification)

    Parameters

    notification

    The NSNotification.

  • Function to set the player URL, you can use it to change the current video stream.

    Declaration

    Swift

    @objc @discardableResult open func handleUrl(_ url: String) -> Bool

    Parameters

    url

    String with the URL.

  • Function to set the player URL Using Fairplay DRM, you can use it to change the current video stream.

    Declaration

    Swift

    @objc open func handleUrl(_ url:String, certificateUrl:String, serverURL:String, jsonResponse:Bool = false)

    Parameters

    url

    String with the URL.

    certificateUrl

    String with the URL.

    serverURL

    String with the URL.

    jsonResponse

    Boolean Specifies whether the response of the verification server is json or not.

  • Function to set the player config URL.

    Declaration

    Swift

    open func setConfigURL(_ url:String)

    Parameters

    url

    String with the URL it must be a json file.

  • Function to set the media object to the sdk

    • paramater object: Media Object

    Declaration

    Swift

    open func setMedia(_ object:MediaObject)
  • Function start the Event Manager

    • paramater url: URL to the text file
    • paramater states: Array of States to verify
    • paramater states: Seconds to try again

    Declaration

    Swift

    open func setEventManager(_ url:String, states:[State], verificationTimeSeconds:Int)
  • Function to set the quality level if the current stream

    • paramater level: a QualityLevel

    Declaration

    Swift

    open func setMaxQualityLevel(level:QualityLevel)
  • Function to set the media url to the sdk

    • paramater url: String with the URL

    Declaration

    Swift

    open func setFeedURL(_ url:String)
  • Function to set the Image Poster

    • paramater image: UIImage with Image poster

    Declaration

    Swift

    open func setPosterImage(_ image:UIImage, parentView:UIView? = nil)
  • Function to set the Image Poster

    • paramater image: String with Image poster url

    Declaration

    Swift

    open func setPosterImage(_ image:String, parentView:UIView? = nil)
  • Function to show the poster image

    Declaration

    Swift

    open func showPosterImage()
  • Function to hide the poster image

    Declaration

    Swift

    open func hidePosterImage()
  • Remove the player observers to avoid memory leaks and zombies.

    Declaration

    Swift

    open func removePlayerItemObservers()
  • Return whether the stream is a live stream or not.

    Declaration

    Swift

    open func isLive() -> Bool

    Return Value

    Whether the stream is a live stream or not.

  • Function to manage the information’s change on the play back

    Declaration

    Swift

    @objc open func playerInfoChanged(_ notification: Notification)

    Parameters

    notification

    The NSNotification

  • Function to manage when the player finished to play an asset

    Declaration

    Swift

    @objc open func playerItemDidPlayToEndTime(_ notification: Notification)

    Parameters

    notification

    The NSNotification

  • Function to manage when the player stalled while playing an asset

    Declaration

    Swift

    @objc open func playerDidStall(_ notification: Notification)

    Parameters

    notification

    The NSNotification

  • Function to manage when the player finished to play an asset

    Declaration

    Swift

    @objc open func playerItemFailedToPlayToEndTime(_ notification: Notification)

    Parameters

    notification

    The NSNotification

  • Function to manage when the position when is playing an asset

    Declaration

    Swift

    @objc open func updatePosition()
  • Plays the stream and sets the playbackState to Playing.

    Declaration

    Swift

    open func play()
  • If the playback ended, plays the same stream from the beginning.

    Declaration

    Swift

    open func replay()
  • Pauses the stream and sets the playbackState to Paused.

    Declaration

    Swift

    open func pause()
  • Destroy the player instance and do player cleanup.

    Declaration

    Swift

    open func stop()
  • Forwards (or rewinds if negative) the stream by the given amount of seconds.

    Declaration

    Swift

    open func jumpToTime(seconds: TimeInterval)

    Parameters

    seconds

    The amount of second to forward (or rewind if negative).

  • Seeks the stream to live.

    Declaration

    Swift

    open func goLive()
  • Seeks the stream to the given position in seconds.

    Declaration

    Swift

    open func seekTo(_ seconds: TimeInterval)

    Parameters

    seconds

    The position in seconds.

  • Returns the duration of the current stream.

    Declaration

    Swift

    open func duration() -> Double

    Return Value

    The duration of the current stream.

  • Returns the current time of the stream.

    Declaration

    Swift

    open func currentTime() -> Double

    Return Value

    The current time of the stream.

  • Sets player speed

    Declaration

    Swift

    open func setPlayerSpeed(_ speed:Float)

    Parameters

    speed

    The player speed 1x, 2x, 3x, etc.

  • Enable or disable the play button overlay

    Declaration

    Swift

    open func overlayButton(enabled:Bool)

    Parameters

    enabled

    true or false.

  • Enable or disable the buffer loading indicator

    Declaration

    Swift

    open func loadingSpinner(enabled:Bool)

    Parameters

    enabled

    true or false.

  • List the available audio tracks

    Declaration

    Swift

    open func getAvailableAudioTracks() -> [String]

    Return Value

    List of Audio Selections Options.

  • Set the media option

    Declaration

    Swift

    open func setMediaCharacteristic(_ mediaCharacteristic:String, type:MediaCharacteristic)

    Parameters

    mediaCharacteristic

    String code for the Media Characteristic.

    type

    String MediaCharacteristic enum.

  • List the available closed captions

    Declaration

    Swift

    open func getAvailableCloseCaptions() -> [String]

    Return Value

    List of Closed Captions Selections Options.

  • Function to set the WebVTT Close Caption File

    • paramater url: String URL to WebVTT Caption File
    • paramater forLanguage: String language name for caption

    Declaration

    Swift

    open func setCloseCaption(url:String, forLanguage:String)
  • Registers an observer to be notified of player events.

    Declaration

    Swift

    @objc open func registerObserver(_ observer: PlayerEventObserver) -> Int

    Parameters

    observer

    The observer to be registered.

    Return Value

    The id of the registered observer.

  • Removes a registered observer.

    Declaration

    Swift

    @objc open func removeObserver(_ id: Int)

    Parameters

    id

    The id of the observer to be removed.

  • Activate Airplay Support.

    Declaration

    Swift

    open func allowAirplayPlayback(_ value:Bool)

    Parameters

    value

    true or false.

  • Verify if Airplay support is enabled.

    Declaration

    Swift

    open func AirPlayPlaybackEnabled() -> Bool

    Return Value

    true or false.

  • Enable logs in the player for debugging.

    Declaration

    Swift

    open func enableLogs()
  • Disable logs in the player for debugging.

    Declaration

    Swift

    open func disableLogs()
  • Returns true if the logs are enabled.

    Declaration

    Swift

    open func logsEnabled() -> Bool

    Return Value

    true or false.

  • Returns true if the log has colors. cancelPlayback

    Declaration

    Swift

    open func logsHasColors() -> Bool

    Return Value

    true or false.