Skip to content

Commit

Permalink
Provide access to the fundamental underlying AVFoundation objects
Browse files Browse the repository at this point in the history
  • Loading branch information
aplr committed Apr 12, 2021
1 parent 7f1f6cb commit 60fea87
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions Sources/Richi/VideoPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,21 @@ public class VideoPlayer: UIView {
updateInternalTimeObserver()
}
}

// MARK: - Interact with AVFoundation Objects

/// The underlying AVPlayer object
open internal(set) lazy var player: AVPlayer = {
let player = AVPlayer()
player.actionAtItemEnd = .none
return player
}()

/// The underlying AVPlayerItem object currently playing
open internal(set) var playerItem: AVPlayerItem? {
get { player.currentItem }
set { player.replaceCurrentItem(with: newValue) }
}

#if canImport(UIKit)
/// :nodoc:
Expand All @@ -185,12 +200,6 @@ public class VideoPlayer: UIView {
layer as! AVPlayerLayer
}

lazy var player: AVPlayer = {
let player = AVPlayer()
player.actionAtItemEnd = .none
return player
}()

// Observers
var playerTimeObserver: Any?
var playerObservers: [NSKeyValueObservation] = []
Expand All @@ -204,12 +213,6 @@ public class VideoPlayer: UIView {
var _preferredMaximumResolution: CGSize = .zero

var pausedReason: Richi.PausedReason = .waitKeepUp

/// The current player item
var playerItem: AVPlayerItem? {
get { player.currentItem }
set { player.replaceCurrentItem(with: newValue) }
}

#if canImport(UIKit)
public override var contentMode: UIView.ContentMode {
Expand Down

0 comments on commit 60fea87

Please sign in to comment.