THEOplayer

@objc
public class THEOplayer : NSObject, EventDispatcherProtocol

The THEOplayer object.

  • The delegate defining behavior for background playback

    Declaration

    Swift

    public var backgroundPlaybackDelegate: BackgroundPlaybackDelegate { get set }
  • Create a new instance of THEOplayer with a frame.

    Declaration

    Swift

    public init(with frame: CGRect? = nil, configuration: THEOplayerConfiguration? = nil)

    Parameters

    frame

    The frame rectangle, which describes the THEOplayer view’s location and size in its superview’s coordinate system, defaults to nil.

    configuration

    A configuration for the new THEOplayer, defaults to nil.

  • THEOplayer’s Version.

    Remark

    Example: "2.77.0"

    Declaration

    Swift

    @objc(playerVersion)
    public static var version: String { get }
  • The frame rectangle, which describes the THEOplayer view’s location and size in its superview’s coordinate system.

    Declaration

    Swift

    @objc
    public var frame: CGRect { get set }
  • The bounds rectangle, which describes the THEOplayer view’s location and size in its own coordinate system.

    Declaration

    Swift

    @objc
    public var bounds: CGRect { get set }
  • The center of the THEOplayer view’s frame.

    Declaration

    Swift

    @objc
    public var center: CGPoint { get set }
  • An integer bit mask that determines how the THEOplayer view resizes itself when its superview’s bounds change.

    Declaration

    Swift

    @objc
    public var autoresizingMask: UIView.AutoresizingMask { get set }
  • Returns the height of the video in pixels for the current quality.

    Declaration

    Swift

    @objc
    public var videoHeight: Int { get }
  • Returns the width of the video in pixels for the current quality.

    Declaration

    Swift

    @objc
    public var videoWidth: Int { get }
  • Returns the current size and position of the video image as displayed within the receiver’s bounds.

    Remark

    This property is key-value observable.

    Declaration

    Swift

    @objc
    dynamic public private(set) var videoRect: CGRect { get }
  • Enables or disables the transition animation when resizing the player. Defaults to true.

    Declaration

    Swift

    @objc
    public var resizeTransitionEnabled: Bool { get set }
  • abr

    Allows you to modify the player’s ABR behavior. See documentation for ABRConfiguration to see how this is done.

    Declaration

    Swift

    @objc
    public var abr: ABRConfiguration { get set }
  • Specifies how to handle the aspect ratio of the content.

    Declaration

    Swift

    @objc
    public var aspectRatio: AspectRatio { get set }
  • The network status of the player which can be used to monitor the network related errors.

    Declaration

    Swift

    public var network: Network { get }
  • The list of Text Tracks.

    Declaration

    Swift

    public var textTracks: TextTrackList { get }
  • The list of Audio Tracks.

    Declaration

    Swift

    public var audioTracks: AudioTrackList { get }
  • The list of Video Tracks.

    Declaration

    Swift

    public var videoTracks: VideoTrackList { get }
  • The length of the currently loaded video, in seconds.

    Declaration

    Swift

    public var duration: Double? { get }
  • Sets or returns if the video should automatically start playing.

    Remark

    • If you set autoplay to true, this will set preload to ‘auto’.
    • Preload will be back to the previous state if you set autoplay back to false.
    • If you want to use autoplay, you should not modify the preload or the autoplay won’t work.

    Declaration

    Swift

    @objc
    public var autoplay: Bool { get set }
  • Sets or returns the current source of the video.

    Remark

    • After invoking the setter, the player sets the provided playback source and applies the provided parameters in the source description.
    • The source description is an object that should be constructed by the user and which should implement the SourceDescription protocol.

    Declaration

    Swift

    @objc
    public var source: SourceDescription? { get set }
  • src

    Returns the current source URL of the video.

    Declaration

    Swift

    @objc
    public var src: String? { get }
  • Sets or returns the volume of the video.

    Declaration

    Swift

    @objc
    public var volume: Float { get set }
  • Sets or returns whether the audio output of the video is muted.

    Declaration

    Swift

    @objc
    public var muted: Bool { get set }
  • Return whether the video is seeking.

    Declaration

    Swift

    @objc
    public var seeking: Bool { get }
  • Returns whether the video is paused.

    Declaration

    Swift

    @objc
    public var paused: Bool { get }
  • Returns whether the video has ended.

    Declaration

    Swift

    @objc
    public var ended: Bool { get }
  • Returns whether the player should preload a certain type of data.

    Remark

    • Default is set to “none”.
    • For all possibilities, see Preload.

    Declaration

    Swift

    @objc
    public var preload: Preload { get set }
  • Returns current playback rate of the player.

    Remark

    1 referring to normal speed.

    Declaration

    Swift

    @objc
    public var playbackRate: Double { get set }
  • Returns the buffered TimeRanges of the player.

    Declaration

    Swift

    @objc
    public var buffered: [TimeRange] { get }
  • Returns the played TimeRanges of the player.

    Declaration

    Swift

    @objc
    public var played: [TimeRange] { get }
  • Returns the seekable TimeRanges of the player.

    Declaration

    Swift

    @objc
    public var seekable: [TimeRange] { get }
  • Returns the Metrics data.

    Declaration

    Swift

    @objc
    public var metrics: Any? { get }
  • Sets or returns the presentationMode of the player.

    Remark

    Declaration

    Swift

    @objc
    public var presentationMode: PresentationMode { get set }
  • Returns the readystate of the player.

    Remark

    • Default is set to HAVE_NOTHING.
    • For all possibilities, see ReadyState.

    Declaration

    Swift

    @objc
    public var readyState: ReadyState { get }
  • Returns the last encountered player error.

    Declaration

    Swift

    @objc
    public var error: String? { get }
  • uid

    Returns the unique ID of the player

    Declaration

    Swift

    @objc
    public var uid: Int { get }
  • The current playback position of the video, in seconds. Setting it allows to change the playback position.

    Declaration

    Swift

    @objc
    public var currentTime: Double { get set }
  • Returns the current playback position of the media, as a timestamp.

    Remark

    Returns nil when the manifest doesn’t specify the currentProgramDateTime.

    Declaration

    Swift

    @objc
    public var currentProgramDateTime: Date? { get }
  • Sets whether THEOplayer automatically manages the AVAudioSession.

    Remark

    • THEOPlayer uses playback as default value for the AVAudioSession.Category.
    • THEOPlayer uses moviePlayback as default value for the AVAudioSession.Mode.

    Declaration

    Swift

    @objc
    public static var automaticallyManageAudioSession: Bool { get set }
  • After invoking this method, the player starts playback.

    Declaration

    Swift

    @objc
    public func play()
  • After invoking this method, the player pauses playback.

    Declaration

    Swift

    @objc
    public func pause()
  • After invoking this method, the player stops playback completely and unloads all loaded resources.

    Remark

    Remark:

    • If the operation completes, the success flag is true and the error is nil.
    • If the operation fails, the success flag is false and the error indicates the problem.

    Declaration

    Swift

    public func stop(completionHandler: ((Bool?, Error?) -> Void)? = nil)

    Parameters

    completionHandler

    An optional closure to invoke when operation completes or fails, defaults to nil. The closure takes two optional arguments: A success flag and an error.

  • Adds the given event listener of the given PlayerEventType.

    Remark

    When attaching a listener on the wrong object the application will crash.

    Declaration

    Swift

    public func addEventListener<E>(type: EventType<E>, listener: @escaping (E) -> ()) -> EventListener where E : EventProtocol

    Parameters

    type

    PlayerEventType of the added event listener.

    listener

    Closure called when event is dispatched.

    Return Value

    EventListener that can be removed.

  • Removes the given event listener of the given PlayerEventType.

    Declaration

    Swift

    public func removeEventListener<E>(type: EventType<E>, listener: EventListener) where E : EventProtocol

    Parameters

    type

    PlayerEventType of the removed event listener.

    listener

    EventListener object that has been returned on addEventListener.

  • Sets the current playback position in the video.

    Declaration

    Swift

    @objc
    public func setCurrentTime(_ newValue: Double, completionHandler: ((Any?, Error?) -> Swift.Void)? = nil)

    Parameters

    newValue

    The new playback position, in seconds.

    completionHandler

    A closure to invoke when operation completes or fails, defaults to nil.

  • Sets the current ProgramDateTime of the player.

    Declaration

    Swift

    @objc
    public func setCurrentProgramDateTime(_ newValue: Date, completionHandler: ((Any?, Error?) -> Swift.Void)? = nil)

    Parameters

    newValue

    The new ProgramDateTime.

    completionHandler

    A closure to invoke when operation completes or fails, defaults to nil.

  • Adds the THEOplayer view to the end of the parameter view’s list of subviews.

    Declaration

    Swift

    @objc
    public func addAsSubview(of view: UIView)

    Parameters

    view

    The view on which the THEOplayer view will be added as a subview.

  • Inserts the THEOplayer view at the specified index of the parameter view’s list of subviews.

    Declaration

    Swift

    @objc
    public func insertAsSubview(of view: UIView, at: Int)

    Parameters

    view

    The view on which the THEOplayer view will be added as a subview.

    at

    The index in the array of the subviews property at which to insert the THEOplayer view. Subview indices start at 0 and cannot be greater than the number of subviews.

  • Inserts the THEOplayer view below another view in the parameter view’s hierarchy.

    Declaration

    Swift

    @objc
    public func insertAsSubview(of view: UIView, belowSubview siblingSubview: UIView)

    Parameters

    view

    The view on which the THEOplayer view will be added as a subview.

    siblingSubview

    The sibling view that will be above the THEOplayer view.

  • Inserts the THEOplayer view above another view in the parameter view’s hierarchy.

    Declaration

    Swift

    @objc
    public func insertAsSubview(of view: UIView, aboveSubview siblingSubview: UIView)

    Parameters

    view

    The view on which the THEOplayer view will be added as a subview.

    siblingSubview

    The sibling view that will be behind the inserted THEOplayer view.

  • Returns a Boolean value indicating whether THEOplayer is contained in the given array of UIview.

    Remark

    Example: self.theoplayer.isContained(in: self.view.subviews)

    Declaration

    Swift

    @objc
    public func isContained(in views: [UIView]) -> Bool

    Parameters

    views

    The array of views in which to search for THEOplayer.

  • Register a content protection integration

    Remark

    Remark:

    Declaration

    Swift

    public static func registerContentProtectionIntegration(integrationId: String, keySystem: KeySystemId, integrationFactory: ContentProtectionIntegrationFactory)

    Parameters

    integrationId

    An id of the integration.

    keySystem

    TheKeySystemId for which theContentProtectionIntegrationFactory should be used.

    integrationFactory

    Factory that will construct a ContentProtectionIntegration.

  • Unloads the THEOplayer.

    Remark

    All future calls to this object will throw an error.

    Declaration

    Swift

    @objc
    public func destroy()
  • Add an Integration to the THEOplayer instance .

    Declaration

    Swift

    @objc
    public func addIntegration(_ integration: Integration)
  • Removes an Integration from the THEOplayer instance.

    Declaration

    Swift

    @objc
    public func removeIntegration(_ integration: Integration)
  • Removes all Integrations from the THEOplayer instance.

    Declaration

    Swift

    @objc
    public func removeAllIntegrations()
  • Returns all registered Integrations on the THEOplayer instance

    Declaration

    Swift

    @objc
    public func getAllIntegrations() -> [Integration]
  • API to configure TextTrack styles (for subtitles)

    Remark

    Only available on the native pipeline.

    Sample usage

    var tts = self.theoplayer?.textTrackStyle
    theoplayer.textTrackStyle?.backgroundColor = [TextTrackStyleRuleColor(UIColor.green)]
    theoplayer.textTrackStyle?.fontColor = [TextTrackStyleRuleColor(UIColor.red)]
    theoplayer.textTrackStyle?.edgeStyle = [TextTrackStyleRuleString(TextTrackStyleEdgeStyle.raised)]
    theoplayer.textTrackStyle?.fontFamily = [TextTrackStyleRuleString("American Typewriter")]
    theoplayer.textTrackStyle?.fontSize = [TextTrackStyleRuleNumber(120)] //20% increase
    theoplayer.textTrackStyle?.marginTop = [TextTrackStyleRuleNumber(0)] // top
    theoplayer.textTrackStyle?.marginLeft = [TextTrackStyleRuleNumber(0)] // left
    

    Declaration

    Swift

    @objc
    public var textTrackStyle: TextTrackStyle? { get }
  • The Cast object helps you configure and control casting to external devices with THEOplayer.

    Declaration

    Swift

    public var cast: Cast? { get }
  • The Fullscreen api of theoplayer.

    Declaration

    Swift

    var fullscreen: Fullscreen { get }
  • Attaches a gesture recognizer to THEOplayer.

    Remark

    Only available on iOS.

    Declaration

    Swift

    @objc
    public func addGestureRecognizer(_ gestureRecognizer: UIGestureRecognizer)
  • Detaches a gesture recognizer from THEOplayer.

    Remark

    Only available on iOS.

    Declaration

    Swift

    @objc
    public func removeGestureRecognizer(_ gestureRecognizer: UIGestureRecognizer)
  • List of the gesture recognizers attached to THEOplayer.

    Remark

    Only available on iOS.

    Declaration

    Swift

    @objc
    public var gestureRecognizers: [UIGestureRecognizer]? { get }
  • ads

    An Ads object that contains information about the current and the scheduled advertisements.

    Declaration

    Swift

    var ads: Ads { get }
  • An Ads object that contains information about the current and the scheduled advertisements.

    Declaration

    Swift

    @objc(ads)
    var ads_Objc: Ads_Objc { get }
  • pip

    A PictureInPicture object to configure Picture-In-Picture.

    Declaration

    Swift

    var pip: PictureInPicture? { get set }
  • Whether the fullscreen mode is coupled to device orientation, defaults to false.

    When enabled, landscape mode will trigger fullscreen mode and portrait mode will trigger non-fullscreen mode.

    Remark

    Changes in the device orientation or fullscreen state will also trigger their coupled mode if enabled.

    Declaration

    Swift

    @objc
    var fullscreenOrientationCoupling: Bool { get set }
  • The Cache object to access the caching API.

    Declaration

    Swift

    static var cache: Cache { get }