Adaptive Media Player

AmpCoreTV 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?
  • Flag to allow the player controls during an ad

    Declaration

    Swift

    @objc open var enableAdUI:Bool = false
  • 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
  • Delegate to handle the playback actions

    Declaration

    Swift

    open var externalPlaybackDelegate: ExternalPlaybackDelegate? = nil
  • 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?
  • Flag to enable or disable the playback on the background

    Important

    While implementing enable Background modes with Audio, Airplay and Picture in Picture

    Declaration

    Swift

    open var allowBackgroundPlayback:Bool = false
  • Flag to enable or disable locked screen widget

    Declaration

    Swift

    open var nowPlayingInfoCenterEnabled = 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>?
  • Returns true or false if an ad is playing

    Important

    If modified you may expirience undesired behaviours

    Declaration

    Swift

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

    Important

    If modified you may expirience undesired behaviours

    Declaration

    Swift

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

    Important

    If modified you may expirience undesired behaviours

    Declaration

    Swift

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

    Important

    If modified you may expirience undesired behaviours

    Declaration

    Swift

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

    Important

    If modified you may expirience undesired behaviours

    Declaration

    Swift

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

    Important

    If modified you may expirience undesired behaviours

    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?
  • Customized view for an inline player instance

  • Customized view for a fullscren player instance

  • 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
  • Metadata at the current time frame (ID3Tags)

    Declaration

    Swift

    @objc open var timedMetadata:[AVMetadataItem]
  • Flag to override the fullscreen validation to check on the toogle state instead of the size of the player.

    Important

    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.

    Declaration

    Swift

    open var overrideDefaultFullscreenBehaviour:Bool = false
  • Read-only flag that indicates if the player is stalled

    Declaration

    Swift

    open var isStalled:Bool
  • Flag to enable or disable the autorecovery feature

    Declaration

    Swift

    open var isAutoRecoveryEnabled = false
  • Returns the current system volume

    Important

    If modified you may expirience undesired behaviours

    Declaration

    Swift

    open var currentSystemVolume:Float = 0.0
  • Return AMP Parent View Controller

  • Return true or false if AMP is on fullscreen mode

  • Return Player Frame

  • Return Full Screen Frame

  • Return true or false if the player supports Picture in Picture

  • Picture in Picture Delegate

  • Enabled or disable the stream verification mode. Default false

    Declaration

    Swift

    open var isStreamAutoRecoveryEnabled:Bool = false
  • Set time rate in seconds to verify if the stream is up or no.

    Declaration

    Swift

    open var streamAutoRecoveryInterval:Double = 10.0
  • Set the stream auto recovery error text

    Declaration

    Swift

    open var streamAutoRecoveryText:String = ""
  • 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()
  • Setter for the player license

    Important

    If the license is invalid you won’t be able to make use of the AMPPlayer or it’s components

    Declaration

    Swift

    open func setLicense(_ license:String)

    Parameters

    license

    Contains the license as an string

  • 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 view for the player

    Declaration

    Swift

    open func setView(_ playerView:AmpPlayerView)

    Parameters

    playerView

    AmpPlayer view

  • Function set the flag to enable the DVR

    Declaration

    Swift

    open func isDVREnabled(_ enabled:Bool)

    Parameters

    enabled

    new flag value

  • Function to set the media object to the sdk

    Declaration

    Swift

    open func setMedia(_ object:MediaObject)

    Parameters

    object

    Media Object

  • Function start the Event Manager

    Declaration

    Swift

    open func setEventManager(_ url:String, states:[State], verificationTimeSeconds:Int)

    Parameters

    url

    URL to the text file

    states

    Seconds to try again

    states

    Seconds to try again

  • Function to set the quality level if the current stream

  • Function to set the media url to the sdk

    Declaration

    Swift

    open func setFeedURL(_ url:String)

    Parameters

    url

    String with the URL

  • Function to set the Image Poster

    Declaration

    Swift

    open func setPoster(_ url:String, type:PosterImageType = .poster ,mode:UIViewContentMode? = nil, parentView:UIView? = nil)

    Parameters

    url

    String with Image poster url

    mode

    Optional UIViewContentMode to display the image on view

    parentView

    Optional UIView with Parent View

  • Function to set the Image Poster

    Declaration

    Swift

    open func setPoster(_ image:UIImage, type:PosterImageType = .poster, mode:UIViewContentMode? = nil, parentView:UIView? = nil)

    Parameters

    url

    String with Image poster url

    mode

    Optional UIViewContentMode to display the image on view

    parentView

    Optional UIView with Parent View

  • Function to show the poster image

    Declaration

    Swift

    open func showPosterImage(type:PosterImageType = .poster)
  • Function to hide the poster image

    Declaration

    Swift

    open func hidePosterImage(type:PosterImageType = .poster)
  • 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 check if the playback matches the end of the video

    Declaration

    Swift

    @objc open func isPlaybackComplete() -> Bool
  • 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()
  • Function to force an update on the playback timebar

    Declaration

    Swift

    @objc open func changePosition()
  • Funtion to the the current framerate of the track

    Declaration

    Swift

    open func getFPS() -> Float

    Return Value

    FPS current value

  • Function to toggle the fullscreen visualization of the player

  • Function to toggle the close captions

    Important

    This only works on custom views
  • Function to show the popup with the available options for close captions

    Important

    This only works on custom views
  • 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.

  • 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.

  • 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.

  • Verify if Chromecast support is enabled.

    Declaration

    Swift

    open func ChromecastPlaybackEnabled() -> 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.