fix: fix the kvo compliance crash when rapidly switching source
This commit is contained in:
parent
a2cdf0f656
commit
1f27ffbc81
@ -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()
|
||||||
@ -269,11 +267,11 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
throw NSError(domain: "", code: 0, userInfo: nil)
|
throw NSError(domain: "", code: 0, userInfo: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
#if canImport(RCTVideoCache)
|
#if canImport(RCTVideoCache)
|
||||||
if self._videoCache.shouldCache(source:source, textTracks:self._textTracks) {
|
if self._videoCache.shouldCache(source:source, textTracks:self._textTracks) {
|
||||||
return self._videoCache.playerItemForSourceUsingCache(uri: source.uri, assetOptions:assetOptions)
|
return self._videoCache.playerItemForSourceUsingCache(uri: source.uri, assetOptions:assetOptions)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if self._drm != nil || self._localSourceEncryptionKeyScheme != nil {
|
if self._drm != nil || self._localSourceEncryptionKeyScheme != nil {
|
||||||
self._resouceLoaderDelegate = RCTResourceLoaderDelegate(
|
self._resouceLoaderDelegate = RCTResourceLoaderDelegate(
|
||||||
@ -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) {
|
||||||
|
Loading…
Reference in New Issue
Block a user