From 60fea87da18cc9c7b04e1f5c20e9e903e4ac2694 Mon Sep 17 00:00:00 2001 From: Andreas Pfurtscheller Date: Mon, 12 Apr 2021 16:19:12 +0200 Subject: [PATCH] Provide access to the fundamental underlying AVFoundation objects --- Sources/Richi/VideoPlayer.swift | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/Sources/Richi/VideoPlayer.swift b/Sources/Richi/VideoPlayer.swift index 00e8cbb..6d08ba6 100644 --- a/Sources/Richi/VideoPlayer.swift +++ b/Sources/Richi/VideoPlayer.swift @@ -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: @@ -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] = [] @@ -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 {