@@ -23,6 +23,8 @@ class VideoView: UIView {
2323
2424 var image : UIImage ?
2525
26+ var autoplay = false
27+
2628 private lazy var loadingIndicator : UIActivityIndicatorView = {
2729 let view = UIActivityIndicatorView ( activityIndicatorStyle: . whiteLarge)
2830 view. autoresizingMask = [ . flexibleLeftMargin, . flexibleTopMargin]
@@ -78,8 +80,11 @@ class VideoView: UIView {
7880
7981 if player. status == . readyToPlay {
8082 self . stopPlayerAndRemoveObserverIfNecessary ( )
81- player. play ( )
82- self . viewDelegate? . videoViewDidStartPlaying ( self )
83+
84+ if self . autoplay {
85+ player. play ( )
86+ self . viewDelegate? . videoViewDidStartPlaying ( self )
87+ }
8388 }
8489 }
8590
@@ -96,7 +101,9 @@ class VideoView: UIView {
96101
97102 var timeObserver : Any ?
98103
99- func start( _ viewerItem: ViewerItem ) {
104+ func start( _ viewerItem: ViewerItem , autoplay: Bool ) {
105+ self . autoplay = autoplay
106+
100107 if let assetID = viewerItem. assetID {
101108 #if os(iOS)
102109 let result = PHAsset . fetchAssets ( withLocalIdentifiers: [ assetID] , options: nil )
@@ -152,12 +159,14 @@ class VideoView: UIView {
152159 self . updateProgressBar ( forDuration: duration, currentTime: currentTime)
153160 }
154161
155- self . playerLayer. isHidden = false
162+ if self . autoplay {
163+ self . playerLayer. isHidden = false
164+ }
156165
157166 if self . shouldRegisterForNotifications {
158167 guard let player = self . playerLayer. player else { fatalError ( " No player item was found " ) }
159168
160- if player. status == . unknown {
169+ if self . autoplay && player. status == . unknown {
161170 self . loadingIndicator. startAnimating ( )
162171 self . loadingIndicatorBackground. alpha = 1
163172 }
0 commit comments