VideoPlayer

public class VideoPlayer : UIView

An object that displays a single video asset or a playlist of video assets in your interface.

Public Properties

  • A value that specifies how the video is displayed within the view’s bounds.

    Declaration

    Swift

    open var gravity: Richi.Gravity { get set }
  • Determines if the video should autoplay

    Declaration

    Swift

    open var autoplay: Bool
  • The audio playback volume for the player.

    Declaration

    Swift

    open var volume: Float { get set }
  • A Boolean value that indicates whether the audio output of the player is muted.

    Declaration

    Swift

    open var isMuted: Bool { get set }
  • A Boolean value that indicates whether video playback prevents display and device sleep.

    Declaration

    Swift

    @available(macOS 10.14, iOS 12.0, tvOS 12.0, *)
    open var preventsDisplaySleepDuringPlayback: Bool { get set }
  • A boolean value that indicates whether video playback is playing

    Declaration

    Swift

    open var isPlaying: Bool { get set }
  • The current playback rate

    Declaration

    Swift

    open var rate: Float { get set }
  • The action to perform when the current player item has finished playing.

    Declaration

    Swift

    open var actionAtEnd: Richi.EndAction

Control Lifecycle Behavior

  • Controls if playback is paused when the application is no longer active. This is because of temporary interruptions such as incoming phone calls, messages or when the app is backgrounded by the user.

    Declaration

    Swift

    open var pauseWhenResigningActive: Bool
  • Controls if playback is paused when the application enters the background. This is triggered by the user sending the app to the background or locking the device.

    Declaration

    Swift

    open var pauseWhenEnteringBackground: Bool
  • Controls if playback is resumed when the application has become active. Playback will be resumed only if the player was paused because of some temporary interruption.

    Declaration

    Swift

    open var resumeWhenBecomingActive: Bool
  • Controls if playback is resumed when the application is about to enter the foreground

    Declaration

    Swift

    open var resumeWhenEnteringForeground: Bool
  • The current asset

    Declaration

    Swift

    open internal(set) var asset: Richi.Asset? { get }
  • Current playback state of the Player

    Declaration

    Swift

    open internal(set) var playbackState: Richi.PlaybackState { get set }
  • Current buffering state of the Player

    Declaration

    Swift

    open internal(set) var bufferingState: Richi.BufferingState { get set }
  • The size of the current video asset.

    Declaration

    Swift

    open var videoSize: CGSize { get }
  • Maximum duration of playback.

    Declaration

    Swift

    open var duration: TimeInterval { get }
  • Media playback’s current time.

    Declaration

    Swift

    open var currentTime: CMTime { get }
  • Indicates the desired limit of network bandwidth consumption for this item.

    Declaration

    Swift

    open var preferredPeakBitRate: Double { get set }
  • Indicates a preferred upper limit on the resolution of the video to be downloaded.

    Declaration

    Swift

    @available(macOS 10.13, iOS 11.0, tvOS 11.0, *)
    open var preferredMaximumResolution: CGSize { get set }
  • Media playback’s current time interval in seconds.

    Declaration

    Swift

    open var currentDuration: TimeInterval { get }
  • The object that acts as the delegate of the video player view

    Declaration

    Swift

    open weak var delegate: VideoPlayerDelegate?
  • The object that acts as the time delegate of the video player view

    Declaration

    Swift

    open weak var timeDelegate: VideoPlayerTimeDelegate? { get set }
  • The time interval at which time observers should notify the progress of the player’s current time.

    Declaration

    Swift

    open var timeObserverInterval: TimeInterval { get set }

Interact with AVFoundation Objects

  • The underlying AVPlayer object

    Declaration

    Swift

    open internal(set) lazy var player: AVPlayer { get set }
  • The underlying AVPlayerItem object currently playing

    Declaration

    Swift

    open internal(set) var playerItem: AVPlayerItem? { get set }
  • Undocumented

    Declaration

    Swift

    public override var contentMode: UIView.ContentMode { get set }

Creating a Video Player

  • Initializes and returns a newly allocated player view object with a zero rect frame.

    Declaration

    Swift

    public init()
  • Initializes and returns a newly allocated player view object from the specified coder.

    Declaration

    Swift

    public required init?(coder: NSCoder)

    Parameters

    coder

    The coder object

Time Publishers

  • Creates a publisher that emits an event when specified times are traversed during normal playback.

    Declaration

    Swift

    @available(macOS 10.15, iOS 13.0, tvOS 13.0, *)
    open func boundaryTimePublisher(forTimes times: [CMTime]) -> AnyPublisher<Void, Never>

    Parameters

    times

    An array of CMTime values representing the times at which to emit events.

    Return Value

    A publisher that emits events when traversing specific times.

  • Creates a publisher that periodically emits the changing time of the current playback.

    Declaration

    Swift

    @available(macOS 10.15, iOS 13.0, tvOS 13.0, *)
    open func periodicTimePublisher(forInterval interval: CMTime) -> AnyPublisher<CMTime, Never>

    Parameters

    interval

    The time interval at which the system invokes the block during normal playback, according to progress of the player’s current time.

    Return Value

    A publisher that emits the changing time.

Managing the Current Asset

  • Loads the given asset and prepares the player. With autoplay enabled, the asset will be played automatically as soon as the player is ready.

    Declaration

    Swift

    open func load(asset: Richi.Asset)

    Parameters

    asset

    The asset to be played

Controlling Playback

  • Plays the current asset from the beginning

    Declaration

    Swift

    open func playFromBeginning()
  • Continues playing the current asset if shouldPlay is true, pauses playback otherwise.

    Declaration

    Swift

    open func play(_ shouldPlay: Bool = true)

    Parameters

    shouldPlay

    Indicates if the player should play or pause

  • Pauses playback of the current asset

    Declaration

    Swift

    open func pause()
  • Stops playback of the current asset.

    Declaration

    Swift

    open func stop()

Seeking through Media

  • Sets the current playback time to the specified time and executes the specified block when the seek operation completes or is interrupted.

    Declaration

    Swift

    open func seek(to time: CMTime, completionHandler: ((Bool) -> Void)? = nil)

    Parameters

    time

    The time to which to seek.

    completionHandler

    The block to invoke when the seek operation has either been completed or been interrupted.

  • Sets the current playback time within a specified time bound and invokes the specified block when the seek operation completes or is interrupted.

    Declaration

    Swift

    open func seek(
        to time: CMTime,
        toleranceBefore: CMTime,
        toleranceAfter: CMTime,
        completionHandler: ((Bool) -> Void)? = nil
    )

    Parameters

    time

    The time to which to seek.

    toleranceBefore

    The tolerance allowed before time.

    toleranceAfter

    The tolerance allowed after time.

    completionHandler

    The block to invoke when the seek operation has either been completed or been interrupted.

  • Captures a snapshot of the current media at the specified time. If time is nil, the current time will be used.

    Declaration

    Swift

    open func snapshot(at time: CMTime? = nil, completion: ((_ image: UIImage?, _ error: Error?) -> Void)?)

    Parameters

    time

    The time at which to capture the snapshot

    completion

    The block to invoke when the snapshot completes. Provides the image if no error occured.

Observing Player Time

  • Requests the invocation of a block when specified times are traversed during normal playback.

    Declaration

    Swift

    open func addBoundaryTimeObserver(
        forTimes times: [CMTime],
        queue: DispatchQueue? = nil,
        using block: @escaping () -> Void
    ) -> Any

    Parameters

    times

    An array of CMTime values representing the times at which to invoke block.

    queue

    A serial queue onto which block should be enqueued. Passing a concurrent queue is not supported and will result in undefined behavior. If you pass nil, the main queue is used.

    block

    The block to be invoked when any of the times in times is crossed during normal playback.

    Return Value

    An opaque object that you pass as the argument to removeTimeObserver(_:) to stop observation.

  • Requests the periodic invocation of a given block during playback to report changing time.

    Declaration

    Swift

    open func addPeriodicTimeObserver(
        forInterval interval: CMTime,
        queue: DispatchQueue? = nil,
        using block: @escaping (CMTime) -> Void
    ) -> Any

    Parameters

    interval

    The time interval at which the system invokes the block during normal playback, according to progress of the player’s current time.

    queue

    The dispatch queue on which the system calls the block. Passing a concurrent queue isn’t supported and results in undefined behavior. If you pass nil, the system uses the main queue.

    block

    The block that the system periodically invokes.

    Return Value

    An opaque object that you pass as the argument to removeTimeObserver(_:) to cancel observation.

  • Cancels a previously registered periodic or boundary time observer.

    Declaration

    Swift

    open func removeTimeObserver(_ observer: Any)

    Parameters

    observer

    An object returned by a previous call to addPeriodicTimeObserver(forInterval:queue:using:) or addBoundaryTimeObserver(forTimes:queue:using:).