chore(linter/swift): add shorthand_optional_binding
rule (#3456)
* chore(linter/swift): add `shorthand_optional_binding` rule * lint code
This commit is contained in:
parent
481cc71eda
commit
2ed3949307
@ -40,6 +40,7 @@ opt_in_rules:
|
|||||||
- redundant_nil_coalescing
|
- redundant_nil_coalescing
|
||||||
- attributes
|
- attributes
|
||||||
- convenience_type
|
- convenience_type
|
||||||
|
- shorthand_optional_binding
|
||||||
analyzer_rules:
|
analyzer_rules:
|
||||||
- explicit_self
|
- explicit_self
|
||||||
- unused_declaration
|
- unused_declaration
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
func requestAds() {
|
func requestAds() {
|
||||||
guard let _video = _video else { return }
|
guard let _video else { return }
|
||||||
// Create ad display container for ad rendering.
|
// Create ad display container for ad rendering.
|
||||||
let adDisplayContainer = IMAAdDisplayContainer(adContainer: _video, viewController: _video.reactViewController())
|
let adDisplayContainer = IMAAdDisplayContainer(adContainer: _video, viewController: _video.reactViewController())
|
||||||
|
|
||||||
@ -57,7 +57,7 @@
|
|||||||
// MARK: - IMAAdsLoaderDelegate
|
// MARK: - IMAAdsLoaderDelegate
|
||||||
|
|
||||||
func adsLoader(_: IMAAdsLoader, adsLoadedWith adsLoadedData: IMAAdsLoadedData) {
|
func adsLoader(_: IMAAdsLoader, adsLoadedWith adsLoadedData: IMAAdsLoadedData) {
|
||||||
guard let _video = _video else { return }
|
guard let _video else { return }
|
||||||
// Grab the instance of the IMAAdsManager and set yourself as the delegate.
|
// Grab the instance of the IMAAdsManager and set yourself as the delegate.
|
||||||
adsManager = adsLoadedData.adsManager
|
adsManager = adsLoadedData.adsManager
|
||||||
adsManager?.delegate = self
|
adsManager?.delegate = self
|
||||||
@ -81,7 +81,7 @@
|
|||||||
// MARK: - IMAAdsManagerDelegate
|
// MARK: - IMAAdsManagerDelegate
|
||||||
|
|
||||||
func adsManager(_ adsManager: IMAAdsManager, didReceive event: IMAAdEvent) {
|
func adsManager(_ adsManager: IMAAdsManager, didReceive event: IMAAdEvent) {
|
||||||
guard let _video = _video else { return }
|
guard let _video else { return }
|
||||||
// Mute ad if the main player is muted
|
// Mute ad if the main player is muted
|
||||||
if _video.isMuted() {
|
if _video.isMuted() {
|
||||||
adsManager.volume = 0
|
adsManager.volume = 0
|
||||||
@ -117,7 +117,7 @@
|
|||||||
print("AdsManager error: " + error.message!)
|
print("AdsManager error: " + error.message!)
|
||||||
}
|
}
|
||||||
|
|
||||||
guard let _video = _video else { return }
|
guard let _video else { return }
|
||||||
|
|
||||||
if _video.onReceiveAdEvent != nil {
|
if _video.onReceiveAdEvent != nil {
|
||||||
_video.onReceiveAdEvent?([
|
_video.onReceiveAdEvent?([
|
||||||
|
@ -18,13 +18,13 @@ import React
|
|||||||
}
|
}
|
||||||
|
|
||||||
func pictureInPictureControllerDidStartPictureInPicture(_: AVPictureInPictureController) {
|
func pictureInPictureControllerDidStartPictureInPicture(_: AVPictureInPictureController) {
|
||||||
guard let _onPictureInPictureStatusChanged = _onPictureInPictureStatusChanged else { return }
|
guard let _onPictureInPictureStatusChanged else { return }
|
||||||
|
|
||||||
_onPictureInPictureStatusChanged()
|
_onPictureInPictureStatusChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
func pictureInPictureControllerDidStopPictureInPicture(_: AVPictureInPictureController) {
|
func pictureInPictureControllerDidStopPictureInPicture(_: AVPictureInPictureController) {
|
||||||
guard let _onPictureInPictureStatusChanged = _onPictureInPictureStatusChanged else { return }
|
guard let _onPictureInPictureStatusChanged else { return }
|
||||||
|
|
||||||
_onPictureInPictureStatusChanged()
|
_onPictureInPictureStatusChanged()
|
||||||
}
|
}
|
||||||
@ -33,7 +33,7 @@ import React
|
|||||||
_: AVPictureInPictureController,
|
_: AVPictureInPictureController,
|
||||||
restoreUserInterfaceForPictureInPictureStopWithCompletionHandler completionHandler: @escaping (Bool) -> Void
|
restoreUserInterfaceForPictureInPictureStopWithCompletionHandler completionHandler: @escaping (Bool) -> Void
|
||||||
) {
|
) {
|
||||||
guard let _onRestoreUserInterfaceForPictureInPictureStop = _onRestoreUserInterfaceForPictureInPictureStop else { return }
|
guard let _onRestoreUserInterfaceForPictureInPictureStop else { return }
|
||||||
|
|
||||||
_onRestoreUserInterfaceForPictureInPictureStop()
|
_onRestoreUserInterfaceForPictureInPictureStop()
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ import React
|
|||||||
}
|
}
|
||||||
|
|
||||||
func setRestoreUserInterfaceForPIPStopCompletionHandler(_ restore: Bool) {
|
func setRestoreUserInterfaceForPIPStopCompletionHandler(_ restore: Bool) {
|
||||||
guard let _restoreUserInterfaceForPIPStopCompletionHandler = _restoreUserInterfaceForPIPStopCompletionHandler else { return }
|
guard let _restoreUserInterfaceForPIPStopCompletionHandler else { return }
|
||||||
_restoreUserInterfaceForPIPStopCompletionHandler(restore)
|
_restoreUserInterfaceForPIPStopCompletionHandler(restore)
|
||||||
self._restoreUserInterfaceForPIPStopCompletionHandler = nil
|
self._restoreUserInterfaceForPIPStopCompletionHandler = nil
|
||||||
}
|
}
|
||||||
@ -61,7 +61,7 @@ import React
|
|||||||
}
|
}
|
||||||
_isActive = isActive
|
_isActive = isActive
|
||||||
|
|
||||||
guard let _pipController = _pipController else { return }
|
guard let _pipController else { return }
|
||||||
|
|
||||||
if _isActive && !_pipController.isPictureInPictureActive {
|
if _isActive && !_pipController.isPictureInPictureActive {
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
|
@ -98,7 +98,7 @@ class RCTPlayerObserver: NSObject, AVPlayerItemMetadataOutputPushDelegate {
|
|||||||
private var _playerViewControllerOverlayFrameObserver: NSKeyValueObservation?
|
private var _playerViewControllerOverlayFrameObserver: NSKeyValueObservation?
|
||||||
|
|
||||||
deinit {
|
deinit {
|
||||||
if let _handlers = _handlers {
|
if let _handlers {
|
||||||
NotificationCenter.default.removeObserver(_handlers)
|
NotificationCenter.default.removeObserver(_handlers)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -206,7 +206,7 @@ class RCTPlayerObserver: NSObject, AVPlayerItemMetadataOutputPushDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func replaceTimeObserverIfSet(_ newUpdateInterval: Float64? = nil) {
|
func replaceTimeObserverIfSet(_ newUpdateInterval: Float64? = nil) {
|
||||||
if let newUpdateInterval = newUpdateInterval {
|
if let newUpdateInterval {
|
||||||
_progressUpdateInterval = newUpdateInterval
|
_progressUpdateInterval = newUpdateInterval
|
||||||
}
|
}
|
||||||
if _timeObserver != nil {
|
if _timeObserver != nil {
|
||||||
|
@ -159,12 +159,12 @@ enum RCTPlayerOperations {
|
|||||||
mediaOption = group.options[index]
|
mediaOption = group.options[index]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if let group = group { // default. invalid type or "system"
|
} else if let group { // default. invalid type or "system"
|
||||||
player?.currentItem?.selectMediaOptionAutomatically(in: group)
|
player?.currentItem?.selectMediaOptionAutomatically(in: group)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if let group = group {
|
if let group {
|
||||||
// If a match isn't found, option will be nil and text tracks will be disabled
|
// If a match isn't found, option will be nil and text tracks will be disabled
|
||||||
player?.currentItem?.select(mediaOption, in: group)
|
player?.currentItem?.select(mediaOption, in: group)
|
||||||
}
|
}
|
||||||
@ -206,7 +206,7 @@ enum RCTPlayerOperations {
|
|||||||
options = .duckOthers
|
options = .duckOthers
|
||||||
}
|
}
|
||||||
|
|
||||||
if let category = category, let options = options {
|
if let category, let options {
|
||||||
do {
|
do {
|
||||||
try audioSession.setCategory(category, options: options)
|
try audioSession.setCategory(category, options: options)
|
||||||
} catch {
|
} catch {
|
||||||
@ -229,13 +229,13 @@ enum RCTPlayerOperations {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
} else if let category = category, options == nil {
|
} else if let category, options == nil {
|
||||||
do {
|
do {
|
||||||
try audioSession.setCategory(category)
|
try audioSession.setCategory(category)
|
||||||
} catch {
|
} catch {
|
||||||
debugPrint("[RCTPlayerOperations] Problem setting up AVAudioSession category. Error: \(error).")
|
debugPrint("[RCTPlayerOperations] Problem setting up AVAudioSession category. Error: \(error).")
|
||||||
}
|
}
|
||||||
} else if category == nil, let options = options {
|
} else if category == nil, let options {
|
||||||
do {
|
do {
|
||||||
try audioSession.setCategory(audioSession.category, options: options)
|
try audioSession.setCategory(audioSession.category, options: options)
|
||||||
} catch {
|
} catch {
|
||||||
|
@ -113,7 +113,7 @@ class RCTResourceLoaderDelegate: NSObject, AVAssetResourceLoaderDelegate, URLSes
|
|||||||
|
|
||||||
func handleEmbeddedKey(_ loadingRequest: AVAssetResourceLoadingRequest!) -> Bool {
|
func handleEmbeddedKey(_ loadingRequest: AVAssetResourceLoadingRequest!) -> Bool {
|
||||||
guard let url = loadingRequest.request.url,
|
guard let url = loadingRequest.request.url,
|
||||||
let _localSourceEncryptionKeyScheme = _localSourceEncryptionKeyScheme,
|
let _localSourceEncryptionKeyScheme,
|
||||||
let persistentKeyData = RCTVideoUtils.extractDataFromCustomSchemeUrl(from: url, scheme: _localSourceEncryptionKeyScheme)
|
let persistentKeyData = RCTVideoUtils.extractDataFromCustomSchemeUrl(from: url, scheme: _localSourceEncryptionKeyScheme)
|
||||||
else {
|
else {
|
||||||
return false
|
return false
|
||||||
@ -139,7 +139,7 @@ class RCTResourceLoaderDelegate: NSObject, AVAssetResourceLoaderDelegate, URLSes
|
|||||||
|
|
||||||
_loadingRequests[requestKey] = loadingRequest
|
_loadingRequests[requestKey] = loadingRequest
|
||||||
|
|
||||||
guard let _drm = _drm, let drmType = _drm.type, drmType == "fairplay" else {
|
guard let _drm, let drmType = _drm.type, drmType == "fairplay" else {
|
||||||
return finishLoadingWithError(error: RCTVideoErrorHandler.noDRMData, licenseUrl: requestKey)
|
return finishLoadingWithError(error: RCTVideoErrorHandler.noDRMData, licenseUrl: requestKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ enum RCTVideoDRM {
|
|||||||
var request = URLRequest(url: URL(string: licenseServer)!)
|
var request = URLRequest(url: URL(string: licenseServer)!)
|
||||||
request.httpMethod = "POST"
|
request.httpMethod = "POST"
|
||||||
|
|
||||||
if let headers = headers {
|
if let headers {
|
||||||
for item in headers {
|
for item in headers {
|
||||||
guard let key = item.key as? String, let value = item.value as? String else {
|
guard let key = item.key as? String, let value = item.value as? String else {
|
||||||
continue
|
continue
|
||||||
@ -90,7 +90,7 @@ enum RCTVideoDRM {
|
|||||||
reject(spcError)
|
reject(spcError)
|
||||||
}
|
}
|
||||||
|
|
||||||
guard let spcData = spcData else {
|
guard let spcData else {
|
||||||
reject(RCTVideoErrorHandler.noSPC)
|
reject(RCTVideoErrorHandler.noSPC)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -101,7 +101,7 @@ enum RCTVideoDRM {
|
|||||||
|
|
||||||
static func createCertificateData(certificateStringUrl: String?, base64Certificate: Bool?) -> Promise<Data> {
|
static func createCertificateData(certificateStringUrl: String?, base64Certificate: Bool?) -> Promise<Data> {
|
||||||
return Promise<Data>(on: .global()) { fulfill, reject in
|
return Promise<Data>(on: .global()) { fulfill, reject in
|
||||||
guard let certificateStringUrl = certificateStringUrl,
|
guard let certificateStringUrl,
|
||||||
let certificateURL = URL(string: certificateStringUrl.addingPercentEncoding(withAllowedCharacters: .urlFragmentAllowed) ?? "") else {
|
let certificateURL = URL(string: certificateStringUrl.addingPercentEncoding(withAllowedCharacters: .urlFragmentAllowed) ?? "") else {
|
||||||
reject(RCTVideoErrorHandler.noCertificateURL)
|
reject(RCTVideoErrorHandler.noCertificateURL)
|
||||||
return
|
return
|
||||||
@ -115,7 +115,7 @@ enum RCTVideoDRM {
|
|||||||
}
|
}
|
||||||
} catch {}
|
} catch {}
|
||||||
|
|
||||||
guard let certificateData = certificateData else {
|
guard let certificateData else {
|
||||||
reject(RCTVideoErrorHandler.noCertificateData)
|
reject(RCTVideoErrorHandler.noCertificateData)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -130,7 +130,7 @@ enum RCTVideoDRM {
|
|||||||
|
|
||||||
return RCTVideoDRM.createCertificateData(certificateStringUrl: certificateUrl, base64Certificate: base64Certificate)
|
return RCTVideoDRM.createCertificateData(certificateStringUrl: certificateUrl, base64Certificate: base64Certificate)
|
||||||
.then { certificateData -> Promise<Data> in
|
.then { certificateData -> Promise<Data> in
|
||||||
guard let contentIdData = contentIdData else {
|
guard let contentIdData else {
|
||||||
throw RCTVideoError.invalidContentId as! Error
|
throw RCTVideoError.invalidContentId as! Error
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,7 +167,7 @@ enum RCTVideoDRM {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
.then { spcData -> Promise<Data> in
|
.then { spcData -> Promise<Data> in
|
||||||
guard let licenseServer = licenseServer else {
|
guard let licenseServer else {
|
||||||
throw RCTVideoError.noLicenseServerURL as! Error
|
throw RCTVideoError.noLicenseServerURL as! Error
|
||||||
}
|
}
|
||||||
return RCTVideoDRM.fetchLicense(
|
return RCTVideoDRM.fetchLicense(
|
||||||
|
@ -12,7 +12,7 @@ enum RCTVideoUtils {
|
|||||||
* \returns The playable duration of the current player item in seconds.
|
* \returns The playable duration of the current player item in seconds.
|
||||||
*/
|
*/
|
||||||
static func calculatePlayableDuration(_ player: AVPlayer?, withSource source: VideoSource?) -> NSNumber {
|
static func calculatePlayableDuration(_ player: AVPlayer?, withSource source: VideoSource?) -> NSNumber {
|
||||||
guard let player = player,
|
guard let player,
|
||||||
let video: AVPlayerItem = player.currentItem,
|
let video: AVPlayerItem = player.currentItem,
|
||||||
video.status == AVPlayerItem.Status.readyToPlay else {
|
video.status == AVPlayerItem.Status.readyToPlay else {
|
||||||
return 0
|
return 0
|
||||||
@ -31,7 +31,7 @@ enum RCTVideoUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let effectiveTimeRange = effectiveTimeRange {
|
if let effectiveTimeRange {
|
||||||
let playableDuration: Float64 = CMTimeGetSeconds(CMTimeRangeGetEnd(effectiveTimeRange))
|
let playableDuration: Float64 = CMTimeGetSeconds(CMTimeRangeGetEnd(effectiveTimeRange))
|
||||||
if playableDuration > 0 {
|
if playableDuration > 0 {
|
||||||
if source?.cropStart != nil {
|
if source?.cropStart != nil {
|
||||||
@ -95,7 +95,7 @@ enum RCTVideoUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static func getAudioTrackInfo(_ player: AVPlayer?) -> [AnyObject]! {
|
static func getAudioTrackInfo(_ player: AVPlayer?) -> [AnyObject]! {
|
||||||
guard let player = player else {
|
guard let player else {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,7 +124,7 @@ enum RCTVideoUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static func getTextTrackInfo(_ player: AVPlayer?) -> [TextTrack]! {
|
static func getTextTrackInfo(_ player: AVPlayer?) -> [TextTrack]! {
|
||||||
guard let player = player else {
|
guard let player else {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,7 +158,7 @@ enum RCTVideoUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static func base64DataFromBase64String(base64String: String?) -> Data? {
|
static func base64DataFromBase64String(base64String: String?) -> Data? {
|
||||||
if let base64String = base64String {
|
if let base64String {
|
||||||
return Data(base64Encoded: base64String)
|
return Data(base64Encoded: base64String)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -216,7 +216,7 @@ enum RCTVideoUtils {
|
|||||||
let videoAsset: AVAssetTrack! = asset.tracks(withMediaType: AVMediaType.video).first
|
let videoAsset: AVAssetTrack! = asset.tracks(withMediaType: AVMediaType.video).first
|
||||||
var validTextTracks: [TextTrack] = []
|
var validTextTracks: [TextTrack] = []
|
||||||
|
|
||||||
if let textTracks = textTracks, !textTracks.isEmpty {
|
if let textTracks, !textTracks.isEmpty {
|
||||||
for i in 0 ..< textTracks.count {
|
for i in 0 ..< textTracks.count {
|
||||||
var textURLAsset: AVURLAsset!
|
var textURLAsset: AVURLAsset!
|
||||||
let textUri: String = textTracks[i].uri
|
let textUri: String = textTracks[i].uri
|
||||||
|
@ -240,7 +240,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
if let userInfo = notification.userInfo {
|
if let userInfo = notification.userInfo {
|
||||||
let reason: AVAudioSession.RouteChangeReason! = userInfo[AVAudioSessionRouteChangeReasonKey] as? AVAudioSession.RouteChangeReason
|
let reason: AVAudioSession.RouteChangeReason! = userInfo[AVAudioSessionRouteChangeReasonKey] as? AVAudioSession.RouteChangeReason
|
||||||
// let previousRoute:NSNumber! = userInfo[AVAudioSessionRouteChangePreviousRouteKey] as? NSNumber
|
// let previousRoute:NSNumber! = userInfo[AVAudioSessionRouteChangePreviousRouteKey] as? NSNumber
|
||||||
if reason == .oldDeviceUnavailable, let onVideoAudioBecomingNoisy = onVideoAudioBecomingNoisy {
|
if reason == .oldDeviceUnavailable, let onVideoAudioBecomingNoisy {
|
||||||
onVideoAudioBecomingNoisy(["target": reactTag as Any])
|
onVideoAudioBecomingNoisy(["target": reactTag as Any])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -307,7 +307,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
// perform on next run loop, otherwise other passed react-props may not be set
|
// perform on next run loop, otherwise other passed react-props may not be set
|
||||||
RCTVideoUtils.delay()
|
RCTVideoUtils.delay()
|
||||||
.then { [weak self] in
|
.then { [weak self] in
|
||||||
guard let self = self else { throw NSError(domain: "", code: 0, userInfo: nil) }
|
guard let self else { throw NSError(domain: "", code: 0, userInfo: nil) }
|
||||||
guard let source = self._source else {
|
guard let source = self._source else {
|
||||||
DebugLog("The source not exist")
|
DebugLog("The source not exist")
|
||||||
throw NSError(domain: "", code: 0, userInfo: nil)
|
throw NSError(domain: "", code: 0, userInfo: nil)
|
||||||
@ -349,7 +349,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
|
|
||||||
return Promise { self.playerItemPrepareText(asset: asset, assetOptions: assetOptions, uri: source.uri ?? "") }
|
return Promise { self.playerItemPrepareText(asset: asset, assetOptions: assetOptions, uri: source.uri ?? "") }
|
||||||
}.then { [weak self] (playerItem: AVPlayerItem!) in
|
}.then { [weak self] (playerItem: AVPlayerItem!) in
|
||||||
guard let self = self else { throw NSError(domain: "", code: 0, userInfo: nil) }
|
guard let self else { throw NSError(domain: "", code: 0, userInfo: nil) }
|
||||||
|
|
||||||
self._player?.pause()
|
self._player?.pause()
|
||||||
self._playerItem = playerItem
|
self._playerItem = playerItem
|
||||||
@ -583,7 +583,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
let seekTime: NSNumber! = info["time"] as! NSNumber
|
let seekTime: NSNumber! = info["time"] as! NSNumber
|
||||||
let seekTolerance: NSNumber! = info["tolerance"] as! NSNumber
|
let seekTolerance: NSNumber! = info["tolerance"] as! NSNumber
|
||||||
let item: AVPlayerItem? = _player?.currentItem
|
let item: AVPlayerItem? = _player?.currentItem
|
||||||
guard item != nil, let player = _player, let item = item, item.status == AVPlayerItem.Status.readyToPlay else {
|
guard item != nil, let player = _player, let item, item.status == AVPlayerItem.Status.readyToPlay else {
|
||||||
_pendingSeek = true
|
_pendingSeek = true
|
||||||
_pendingSeekTime = seekTime.floatValue
|
_pendingSeekTime = seekTime.floatValue
|
||||||
return
|
return
|
||||||
@ -598,7 +598,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
seekTolerance: seekTolerance.floatValue
|
seekTolerance: seekTolerance.floatValue
|
||||||
)
|
)
|
||||||
.then { [weak self] (_: Bool) in
|
.then { [weak self] (_: Bool) in
|
||||||
guard let self = self else { return }
|
guard let self else { return }
|
||||||
|
|
||||||
self._playerObserver.addTimeObserverIfNotSet()
|
self._playerObserver.addTimeObserverIfNotSet()
|
||||||
if !wasPaused {
|
if !wasPaused {
|
||||||
@ -711,7 +711,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
// Fallback on earlier versions
|
// Fallback on earlier versions
|
||||||
}
|
}
|
||||||
|
|
||||||
if let _maxBitRate = _maxBitRate {
|
if let _maxBitRate {
|
||||||
setMaxBitRate(_maxBitRate)
|
setMaxBitRate(_maxBitRate)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -811,7 +811,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
}
|
}
|
||||||
|
|
||||||
viewController.present(playerViewController, animated: true, completion: { [weak self] in
|
viewController.present(playerViewController, animated: true, completion: { [weak self] in
|
||||||
guard let self = self else { return }
|
guard let self else { return }
|
||||||
// In fullscreen we must display controls
|
// In fullscreen we must display controls
|
||||||
self._playerViewController?.showsPlaybackControls = true
|
self._playerViewController?.showsPlaybackControls = true
|
||||||
self._fullscreenPlayerPresented = fullscreen
|
self._fullscreenPlayerPresented = fullscreen
|
||||||
@ -821,7 +821,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if !fullscreen && _fullscreenPlayerPresented, let _playerViewController = _playerViewController {
|
} else if !fullscreen && _fullscreenPlayerPresented, let _playerViewController {
|
||||||
self.videoPlayerViewControllerWillDismiss(playerViewController: _playerViewController)
|
self.videoPlayerViewControllerWillDismiss(playerViewController: _playerViewController)
|
||||||
_presentingViewController?.dismiss(animated: true, completion: { [weak self] in
|
_presentingViewController?.dismiss(animated: true, completion: { [weak self] in
|
||||||
self?.videoPlayerViewControllerDidDismiss(playerViewController: _playerViewController)
|
self?.videoPlayerViewControllerDidDismiss(playerViewController: _playerViewController)
|
||||||
@ -846,7 +846,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
}
|
}
|
||||||
|
|
||||||
func usePlayerViewController() {
|
func usePlayerViewController() {
|
||||||
guard let _player = _player, let _playerItem = _playerItem else { return }
|
guard let _player, let _playerItem else { return }
|
||||||
|
|
||||||
if _playerViewController == nil {
|
if _playerViewController == nil {
|
||||||
_playerViewController = createPlayerViewController(player: _player, withPlayerItem: _playerItem)
|
_playerViewController = createPlayerViewController(player: _player, withPlayerItem: _playerItem)
|
||||||
@ -855,7 +855,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
// resize mode must be set before subview is added
|
// resize mode must be set before subview is added
|
||||||
setResizeMode(_resizeMode)
|
setResizeMode(_resizeMode)
|
||||||
|
|
||||||
guard let _playerViewController = _playerViewController else { return }
|
guard let _playerViewController else { return }
|
||||||
|
|
||||||
if _controls {
|
if _controls {
|
||||||
let viewController: UIViewController! = self.reactViewController()
|
let viewController: UIViewController! = self.reactViewController()
|
||||||
@ -881,7 +881,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
}
|
}
|
||||||
|
|
||||||
func usePlayerLayer() {
|
func usePlayerLayer() {
|
||||||
if let _player = _player {
|
if let _player {
|
||||||
_playerLayer = AVPlayerLayer(player: _player)
|
_playerLayer = AVPlayerLayer(player: _player)
|
||||||
_playerLayer?.frame = self.bounds
|
_playerLayer?.frame = self.bounds
|
||||||
_playerLayer?.needsDisplayOnBoundsChange = true
|
_playerLayer?.needsDisplayOnBoundsChange = true
|
||||||
@ -891,7 +891,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
setResizeMode(_resizeMode)
|
setResizeMode(_resizeMode)
|
||||||
_playerObserver.playerLayer = _playerLayer
|
_playerObserver.playerLayer = _playerLayer
|
||||||
|
|
||||||
if let _playerLayer = _playerLayer {
|
if let _playerLayer {
|
||||||
self.layer.addSublayer(_playerLayer)
|
self.layer.addSublayer(_playerLayer)
|
||||||
}
|
}
|
||||||
self.layer.needsDisplayOnBoundsChange = true
|
self.layer.needsDisplayOnBoundsChange = true
|
||||||
@ -934,7 +934,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
func videoPlayerViewControllerWillDismiss(playerViewController: AVPlayerViewController) {
|
func videoPlayerViewControllerWillDismiss(playerViewController: AVPlayerViewController) {
|
||||||
if _playerViewController == playerViewController
|
if _playerViewController == playerViewController
|
||||||
&& _fullscreenPlayerPresented,
|
&& _fullscreenPlayerPresented,
|
||||||
let onVideoFullscreenPlayerWillDismiss = onVideoFullscreenPlayerWillDismiss {
|
let onVideoFullscreenPlayerWillDismiss {
|
||||||
_playerObserver.removePlayerViewControllerObservers()
|
_playerObserver.removePlayerViewControllerObservers()
|
||||||
onVideoFullscreenPlayerWillDismiss(["target": reactTag as Any])
|
onVideoFullscreenPlayerWillDismiss(["target": reactTag as Any])
|
||||||
}
|
}
|
||||||
@ -965,7 +965,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
}
|
}
|
||||||
|
|
||||||
let filter: CIFilter! = CIFilter(name: filterName)
|
let filter: CIFilter! = CIFilter(name: filterName)
|
||||||
if #available(iOS 9.0, *), let _playerItem = _playerItem {
|
if #available(iOS 9.0, *), let _playerItem {
|
||||||
self._playerItem?.videoComposition = AVVideoComposition(
|
self._playerItem?.videoComposition = AVVideoComposition(
|
||||||
asset: _playerItem.asset,
|
asset: _playerItem.asset,
|
||||||
applyingCIFiltersWithHandler: { (request: AVAsynchronousCIImageFilteringRequest) in
|
applyingCIFiltersWithHandler: { (request: AVAsynchronousCIImageFilteringRequest) in
|
||||||
@ -1032,7 +1032,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
|
|
||||||
override func layoutSubviews() {
|
override func layoutSubviews() {
|
||||||
super.layoutSubviews()
|
super.layoutSubviews()
|
||||||
if _controls, let _playerViewController = _playerViewController {
|
if _controls, let _playerViewController {
|
||||||
_playerViewController.view.frame = bounds
|
_playerViewController.view.frame = bounds
|
||||||
|
|
||||||
// also adjust all subviews of contentOverlayView
|
// also adjust all subviews of contentOverlayView
|
||||||
@ -1057,7 +1057,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
|
|
||||||
self.removePlayerLayer()
|
self.removePlayerLayer()
|
||||||
|
|
||||||
if let _playerViewController = _playerViewController {
|
if let _playerViewController {
|
||||||
_playerViewController.view.removeFromSuperview()
|
_playerViewController.view.removeFromSuperview()
|
||||||
_playerViewController.removeFromParent()
|
_playerViewController.removeFromParent()
|
||||||
_playerViewController.rctDelegate = nil
|
_playerViewController.rctDelegate = nil
|
||||||
@ -1120,7 +1120,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
let value = item.value as? String
|
let value = item.value as? String
|
||||||
let identifier = item.identifier?.rawValue
|
let identifier = item.identifier?.rawValue
|
||||||
|
|
||||||
if let value = value {
|
if let value {
|
||||||
metadata.append(["value": value, "identifier": identifier])
|
metadata.append(["value": value, "identifier": identifier])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1133,7 +1133,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
|
|
||||||
// Handle player item status change.
|
// Handle player item status change.
|
||||||
func handlePlayerItemStatusChange(playerItem _: AVPlayerItem, change _: NSKeyValueObservedChange<AVPlayerItem.Status>) {
|
func handlePlayerItemStatusChange(playerItem _: AVPlayerItem, change _: NSKeyValueObservedChange<AVPlayerItem.Status>) {
|
||||||
guard let _playerItem = _playerItem else {
|
guard let _playerItem else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1145,7 +1145,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
}
|
}
|
||||||
|
|
||||||
func handleReadyToPlay() {
|
func handleReadyToPlay() {
|
||||||
guard let _playerItem = _playerItem else { return }
|
guard let _playerItem else { return }
|
||||||
var duration = Float(CMTimeGetSeconds(_playerItem.asset.duration))
|
var duration = Float(CMTimeGetSeconds(_playerItem.asset.duration))
|
||||||
|
|
||||||
if duration.isNaN {
|
if duration.isNaN {
|
||||||
@ -1217,7 +1217,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
}
|
}
|
||||||
|
|
||||||
func handlePlaybackFailed() {
|
func handlePlaybackFailed() {
|
||||||
guard let _playerItem = _playerItem else { return }
|
guard let _playerItem else { return }
|
||||||
onVideoError?(
|
onVideoError?(
|
||||||
[
|
[
|
||||||
"error": [
|
"error": [
|
||||||
@ -1249,7 +1249,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
}
|
}
|
||||||
|
|
||||||
func handlePlaybackRateChange(player: AVPlayer, change: NSKeyValueObservedChange<Float>) {
|
func handlePlaybackRateChange(player: AVPlayer, change: NSKeyValueObservedChange<Float>) {
|
||||||
guard let _player = _player else { return }
|
guard let _player else { return }
|
||||||
|
|
||||||
if player.rate == change.oldValue && change.oldValue != nil {
|
if player.rate == change.oldValue && change.oldValue != nil {
|
||||||
return
|
return
|
||||||
@ -1269,7 +1269,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
}
|
}
|
||||||
|
|
||||||
func handleVolumeChange(player: AVPlayer, change: NSKeyValueObservedChange<Float>) {
|
func handleVolumeChange(player: AVPlayer, change: NSKeyValueObservedChange<Float>) {
|
||||||
guard let _player = _player else { return }
|
guard let _player else { return }
|
||||||
|
|
||||||
if player.rate == change.oldValue && change.oldValue != nil {
|
if player.rate == change.oldValue && change.oldValue != nil {
|
||||||
return
|
return
|
||||||
@ -1280,7 +1280,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
}
|
}
|
||||||
|
|
||||||
func handleExternalPlaybackActiveChange(player _: AVPlayer, change _: NSKeyValueObservedChange<Bool>) {
|
func handleExternalPlaybackActiveChange(player _: AVPlayer, change _: NSKeyValueObservedChange<Bool>) {
|
||||||
guard let _player = _player else { return }
|
guard let _player else { return }
|
||||||
onVideoExternalPlaybackChange?(["isExternalPlaybackActive": NSNumber(value: _player.isExternalPlaybackActive),
|
onVideoExternalPlaybackChange?(["isExternalPlaybackActive": NSNumber(value: _player.isExternalPlaybackActive),
|
||||||
"target": reactTag as Any])
|
"target": reactTag as Any])
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ class RCTVideoCachingHandler: NSObject, DVAssetLoaderDelegatesDelegate {
|
|||||||
let url = URL(string: uri)
|
let url = URL(string: uri)
|
||||||
return getItemForUri(uri)
|
return getItemForUri(uri)
|
||||||
.then { [weak self] (videoCacheStatus: RCTVideoCacheStatus, cachedAsset: AVAsset?) -> AVPlayerItem in
|
.then { [weak self] (videoCacheStatus: RCTVideoCacheStatus, cachedAsset: AVAsset?) -> AVPlayerItem in
|
||||||
guard let self = self, let playerItemPrepareText = self.playerItemPrepareText else { throw NSError(domain: "", code: 0, userInfo: nil) }
|
guard let self, let playerItemPrepareText = self.playerItemPrepareText else { throw NSError(domain: "", code: 0, userInfo: nil) }
|
||||||
switch videoCacheStatus {
|
switch videoCacheStatus {
|
||||||
case .missingFileExtension:
|
case .missingFileExtension:
|
||||||
DebugLog("""
|
DebugLog("""
|
||||||
@ -53,7 +53,7 @@ class RCTVideoCachingHandler: NSObject, DVAssetLoaderDelegatesDelegate {
|
|||||||
return playerItemPrepareText(asset, options, "")
|
return playerItemPrepareText(asset, options, "")
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if let cachedAsset = cachedAsset {
|
if let cachedAsset {
|
||||||
DebugLog("Playing back uri '\(uri)' from cache")
|
DebugLog("Playing back uri '\(uri)' from cache")
|
||||||
// See note in playerItemForSource about not being able to support text tracks & caching
|
// See note in playerItemForSource about not being able to support text tracks & caching
|
||||||
return AVPlayerItem(asset: cachedAsset)
|
return AVPlayerItem(asset: cachedAsset)
|
||||||
|
Loading…
Reference in New Issue
Block a user