Merge pull request #2917 from wood1986/bug/kvo-crash

fix: fix the kvo compliance crash when rapidly switching source
This commit is contained in:
Olivier Bouillet 2022-12-17 22:35:50 +01:00 committed by GitHub
commit 685a626542
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -233,14 +233,12 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
} }
// MARK: - Player and source // MARK: - Player and source
@objc @objc
func setSrc(_ source:NSDictionary!) { func setSrc(_ source:NSDictionary!) {
DispatchQueue.global(qos: .default).async {
_source = VideoSource(source) _source = VideoSource(source)
if (_source?.uri == nil || _source?.uri == "") { if (_source?.uri == nil || _source?.uri == "") {
DispatchQueue.global(qos: .default).async {
self._player?.replaceCurrentItem(with: nil) self._player?.replaceCurrentItem(with: nil)
}
return; return;
} }
removePlayerLayer() removePlayerLayer()
@ -299,9 +297,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
} }
self._player = self._player ?? AVPlayer() self._player = self._player ?? AVPlayer()
DispatchQueue.global(qos: .default).async { self._player.replaceCurrentItem(with: playerItem)
self._player?.replaceCurrentItem(with: playerItem)
}
self._playerObserver.player = self._player self._playerObserver.player = self._player
self.applyModifiers() self.applyModifiers()
self._player?.actionAtItemEnd = .none self._player?.actionAtItemEnd = .none
@ -310,13 +306,6 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
self.setAutomaticallyWaitsToMinimizeStalling(self._automaticallyWaitsToMinimizeStalling) self.setAutomaticallyWaitsToMinimizeStalling(self._automaticallyWaitsToMinimizeStalling)
} }
if self._adTagUrl != nil {
// Set up your content playhead and contentComplete callback.
self._contentPlayhead = IMAAVPlayerContentPlayhead(avPlayer: self._player!)
self._imaAdsManager.setUpAdsLoader()
}
//Perform on next run loop, otherwise onVideoLoadStart is nil //Perform on next run loop, otherwise onVideoLoadStart is nil
self.onVideoLoadStart?([ self.onVideoLoadStart?([
"src": [ "src": [
@ -330,6 +319,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
}.catch{_ in } }.catch{_ in }
_videoLoadStarted = true _videoLoadStarted = true
} }
}
@objc @objc
func setDrm(_ drm:NSDictionary) { func setDrm(_ drm:NSDictionary) {