VideoPlayer

open class VideoPlayer : UIViewController

Video Player, simple way to play and stream media

@see https://github.com/piemonte/Player

  • Player delegate.

    Declaration

    Swift

    open weak var playerDelegate: VideoPlayerDelegate?
  • Playback delegate.

    Declaration

    Swift

    open weak var playbackDelegate: VideoPlayerPlaybackDelegate?
  • url

    Local or remote URL for the file asset to be played. URL of the asset.

    Declaration

    Swift

    open var url: URL? { get set }
  • For setting up with AVAsset instead of URL Note: This will reset the url property. (cannot set both)

    Declaration

    Swift

    open var asset: AVAsset? { get set }
  • Specifies how the video is displayed within a player layer’s bounds. The default value is AVLayerVideoGravityResizeAspect. See PlayerFillMode.

    Declaration

    Swift

    open var fillMode: AVLayerVideoGravity { get set }
  • Determines if the video should autoplay when streaming a URL.

    Declaration

    Swift

    open var autoplay: Bool
  • Mutes audio playback when true.

    Declaration

    Swift

    open var muted: Bool { get set }
  • Volume for the player, ranging from 0.0 to 1.0 on a linear scale.

    Declaration

    Swift

    open var volume: Float { get set }
  • Rate at which the video should play once it loads

    Declaration

    Swift

    open var rate: Float { get set }
  • Pauses playback automatically when resigning active.

    Declaration

    Swift

    open var playbackPausesWhenResigningActive: Bool
  • Pauses playback automatically when backgrounded.

    Declaration

    Swift

    open var playbackPausesWhenBackgrounded: Bool
  • Resumes playback when became active.

    Declaration

    Swift

    open var playbackResumesWhenBecameActive: Bool
  • Resumes playback when entering foreground.

    Declaration

    Swift

    open var playbackResumesWhenEnteringForeground: Bool
  • Undocumented

    Declaration

    Swift

    open var isPlayingVideo: Bool { get }
  • Playback automatically loops continuously when true.

    Declaration

    Swift

    open var playbackLoops: Bool { get set }
  • Playback freezes on last frame frame when true and does not reset seek position timestamp..

    Declaration

    Swift

    open var playbackFreezesAtEnd: Bool
  • Current playback state of the Player.

    Declaration

    Swift

    open var playbackState: VideoPlayerPlaybackState { get set }
  • Current buffering state of the Player.

    Declaration

    Swift

    open var bufferingState: VideoPlayerBufferingState { get set }
  • Playback buffering size in seconds.

    Declaration

    Swift

    open var bufferSizeInSeconds: Double
  • Playback is not automatically triggered from state changes when true.

    Declaration

    Swift

    open var playbackEdgeTriggered: Bool
  • Maximum duration of playback.

    Declaration

    Swift

    open var maximumDuration: TimeInterval { get }
  • Media playback’s current time interval in seconds.

    Declaration

    Swift

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

    Declaration

    Swift

    open var currentTime: CMTime { get }
  • The natural dimensions of the media.

    Declaration

    Swift

    open var naturalSize: CGSize { get }
  • Undocumented

    Declaration

    Swift

    open lazy var player: AVPlayer { get set }
  • Undocumented

    Declaration

    Swift

    open lazy var playerView: VideoPlayerView { get set }
  • Return the av player layer for consumption by things such as Picture in Picture

    Declaration

    Swift

    open func playerLayer() -> AVPlayerLayer?
  • 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

    open var preferredMaximumResolution: CGSize { get set }

lifecycle

  • Undocumented

    Declaration

    Swift

    public convenience init()
  • Undocumented

    Declaration

    Swift

    public required init?(coder aDecoder: NSCoder)
  • Undocumented

    Declaration

    Swift

    public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?)
  • Undocumented

    Declaration

    Swift

    open override func loadView()
  • Undocumented

    Declaration

    Swift

    open override func viewDidLoad()
  • Undocumented

    Declaration

    Swift

    open override func viewDidDisappear(_ animated: Bool)

performance

  • Total time spent playing.

    Declaration

    Swift

    public var totalDurationWatched: TimeInterval { get }

actions

  • Begins playback of the media from the beginning.

    Declaration

    Swift

    open func playFromBeginning()
  • Begins playback of the media from the current time.

    Declaration

    Swift

    open func playFromCurrentTime()
  • Pauses playback of the media.

    Declaration

    Swift

    open func pause()
  • Stops playback of the media.

    Declaration

    Swift

    open func stop()
  • Updates playback to the specified time.

    Declaration

    Swift

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

    Parameters

    time

    The time to switch to move the playback.

    completionHandler

    Call block handler after seeking/

  • Updates the playback time to the specified time bound.

    Declaration

    Swift

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

    Parameters

    time

    The time to switch to move the playback.

    toleranceBefore

    The tolerance allowed before time.

    toleranceAfter

    The tolerance allowed after time.

    completionHandler

    call block handler after seeking

  • Captures a snapshot of the current Player asset.

    Declaration

    Swift

    open func takeSnapshot(completionHandler: ((_ image: UIImage?, _ error: Error?) -> Void)?)

    Parameters

    completionHandler

    Returns a UIImage of the requested video frame. (Great for thumbnails!)