chore(ios): remove some warnings (#4159)

This commit is contained in:
Olivier Bouillet 2024-09-13 10:49:43 +02:00 committed by GitHub
parent 2c1fc964bf
commit 7118ba6819
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 40 additions and 52 deletions

View File

@ -48,7 +48,7 @@ class VideoPluginSample: NSObject, RNVPlugin {
* custom functions to be able to track AVPlayer state change * custom functions to be able to track AVPlayer state change
*/ */
func handlePlaybackRateChange(player: AVPlayer, change: NSKeyValueObservedChange<Float>) { func handlePlaybackRateChange(player: AVPlayer, change: NSKeyValueObservedChange<Float>) {
NSLog("plugin: handlePlaybackRateChange \(change.oldValue)") NSLog("plugin: handlePlaybackRateChange \(String(describing: change.oldValue))")
} }
func handlePlayerItemStatusChange(playerItem: AVPlayerItem, change _: NSKeyValueObservedChange<AVPlayerItem.Status>) { func handlePlayerItemStatusChange(playerItem: AVPlayerItem, change _: NSKeyValueObservedChange<AVPlayerItem.Status>) {
@ -56,7 +56,7 @@ class VideoPluginSample: NSObject, RNVPlugin {
} }
func handleCurrentItemChange(player: AVPlayer, change: NSKeyValueObservedChange<AVPlayerItem?>) { func handleCurrentItemChange(player: AVPlayer, change: NSKeyValueObservedChange<AVPlayerItem?>) {
NSLog("plugin: handleCurrentItemChange \(player.currentItem)") NSLog("plugin: handleCurrentItemChange \(String(describing: player.currentItem))")
guard let playerItem = player.currentItem else { guard let playerItem = player.currentItem else {
_playerItemStatusObserver?.invalidate() _playerItemStatusObserver?.invalidate()
return return

View File

@ -234,11 +234,10 @@ class RCTPlayerObserver: NSObject, AVPlayerItemMetadataOutputPushDelegate, AVPla
/* Cancels the previously registered time observer. */ /* Cancels the previously registered time observer. */
func removePlayerTimeObserver() { func removePlayerTimeObserver() {
if _timeObserver != nil { guard let timeObserver = _timeObserver else { return }
player?.removeTimeObserver(_timeObserver) player?.removeTimeObserver(timeObserver)
_timeObserver = nil _timeObserver = nil
} }
}
func addTimeObserverIfNotSet() { func addTimeObserverIfNotSet() {
if _timeObserver == nil { if _timeObserver == nil {

View File

@ -49,7 +49,7 @@ class RCTResourceLoaderDelegate: NSObject, AVAssetResourceLoaderDelegate, URLSes
func setLicenseResult(_ license: String!, _ licenseUrl: String!) { func setLicenseResult(_ license: String!, _ licenseUrl: String!) {
// Check if the loading request exists in _loadingRequests based on licenseUrl // Check if the loading request exists in _loadingRequests based on licenseUrl
guard let loadingRequest = _loadingRequests[licenseUrl] else { guard let loadingRequest = _loadingRequests[licenseUrl] else {
setLicenseResultError("Loading request for licenseUrl \(licenseUrl) not found", licenseUrl) setLicenseResultError("Loading request for licenseUrl \(String(describing: licenseUrl)) not found", licenseUrl)
return return
} }
@ -87,12 +87,12 @@ class RCTResourceLoaderDelegate: NSObject, AVAssetResourceLoaderDelegate, URLSes
_onVideoError?([ _onVideoError?([
"error": [ "error": [
"code": NSNumber(value: error.code), "code": NSNumber(value: error.code),
"localizedDescription": error.localizedDescription ?? "", "localizedDescription": error.localizedDescription,
"localizedFailureReason": error.localizedFailureReason ?? "", "localizedFailureReason": error.localizedFailureReason ?? "",
"localizedRecoverySuggestion": error.localizedRecoverySuggestion ?? "", "localizedRecoverySuggestion": error.localizedRecoverySuggestion ?? "",
"domain": error.domain, "domain": error.domain,
], ],
"target": _reactTag, "target": _reactTag as Any,
]) ])
return false return false
@ -158,7 +158,7 @@ class RCTResourceLoaderDelegate: NSObject, AVAssetResourceLoaderDelegate, URLSes
"loadedLicenseUrl": loadingRequest.request.url?.absoluteString ?? "", "loadedLicenseUrl": loadingRequest.request.url?.absoluteString ?? "",
"contentId": contentId ?? "", "contentId": contentId ?? "",
"spcBase64": spcData.base64EncodedString(options: []), "spcBase64": spcData.base64EncodedString(options: []),
"target": self._reactTag]) "target": self._reactTag as Any])
} else { } else {
let data = try await RCTVideoDRM.handleInternalGetLicense( let data = try await RCTVideoDRM.handleInternalGetLicense(
loadingRequest: loadingRequest, loadingRequest: loadingRequest,

View File

@ -60,13 +60,11 @@ enum RCTVideoSave {
static func ensureDirExists(withPath path: String?) -> Bool { static func ensureDirExists(withPath path: String?) -> Bool {
var isDir: ObjCBool = false var isDir: ObjCBool = false
var error: Error?
let exists = FileManager.default.fileExists(atPath: path ?? "", isDirectory: &isDir) let exists = FileManager.default.fileExists(atPath: path ?? "", isDirectory: &isDir)
if !(exists && isDir.boolValue) { if !(exists && isDir.boolValue) {
do { do {
try FileManager.default.createDirectory(atPath: path ?? "", withIntermediateDirectories: true, attributes: nil) try FileManager.default.createDirectory(atPath: path ?? "", withIntermediateDirectories: true, attributes: nil)
} catch {} } catch {
if error != nil {
return false return false
} }
} }

View File

@ -179,12 +179,11 @@ enum RCTVideoUtils {
title = value as! String title = value as! String
} }
let language: String! = currentOption?.extendedLanguageTag ?? "" let language: String! = currentOption?.extendedLanguageTag ?? ""
let selectedOpt = player.currentItem?.currentMediaSelection
let selectedOption: AVMediaSelectionOption? = player.currentItem?.currentMediaSelection.selectedMediaOption(in: group!) let selectedOption: AVMediaSelectionOption? = player.currentItem?.currentMediaSelection.selectedMediaOption(in: group!)
let textTrack = TextTrack([ let textTrack = TextTrack([
"index": NSNumber(value: i), "index": NSNumber(value: i),
"title": title, "title": title,
"language": language, "language": language as Any,
"selected": currentOption?.displayName == selectedOption?.displayName, "selected": currentOption?.displayName == selectedOption?.displayName,
]) ])
textTracks.append(textTrack) textTracks.append(textTrack)
@ -375,8 +374,8 @@ enum RCTVideoUtils {
assetOptions.setObject(headers, forKey: "AVURLAssetHTTPHeaderFieldsKey" as NSCopying) assetOptions.setObject(headers, forKey: "AVURLAssetHTTPHeaderFieldsKey" as NSCopying)
} }
let cookies: [AnyObject]! = HTTPCookieStorage.shared.cookies let cookies: [AnyObject]! = HTTPCookieStorage.shared.cookies
assetOptions.setObject(cookies, forKey: AVURLAssetHTTPCookiesKey as NSCopying) assetOptions.setObject(cookies as Any, forKey: AVURLAssetHTTPCookiesKey as NSCopying)
asset = AVURLAsset(url: url!, options: assetOptions as! [String: Any]) asset = AVURLAsset(url: url!, options: assetOptions as? [String: Any])
} else { } else {
asset = AVURLAsset(url: url!) asset = AVURLAsset(url: url!)
} }
@ -431,30 +430,22 @@ enum RCTVideoUtils {
return try? await AVVideoComposition.videoComposition( return try? await AVVideoComposition.videoComposition(
with: asset, with: asset,
applyingCIFiltersWithHandler: { (request: AVAsynchronousCIImageFilteringRequest) in applyingCIFiltersWithHandler: { (request: AVAsynchronousCIImageFilteringRequest) in
if filter == nil {
request.finish(with: request.sourceImage, context: nil)
} else {
let image: CIImage! = request.sourceImage.clampedToExtent() let image: CIImage! = request.sourceImage.clampedToExtent()
filter.setValue(image, forKey: kCIInputImageKey) filter.setValue(image, forKey: kCIInputImageKey)
let output: CIImage! = filter.outputImage?.cropped(to: request.sourceImage.extent) let output: CIImage! = filter.outputImage?.cropped(to: request.sourceImage.extent)
request.finish(with: output, context: nil) request.finish(with: output, context: nil)
} }
}
) )
} else { } else {
#if !os(visionOS) #if !os(visionOS)
return AVVideoComposition( return AVVideoComposition(
asset: asset, asset: asset,
applyingCIFiltersWithHandler: { (request: AVAsynchronousCIImageFilteringRequest) in applyingCIFiltersWithHandler: { (request: AVAsynchronousCIImageFilteringRequest) in
if filter == nil {
request.finish(with: request.sourceImage, context: nil)
} else {
let image: CIImage! = request.sourceImage.clampedToExtent() let image: CIImage! = request.sourceImage.clampedToExtent()
filter.setValue(image, forKey: kCIInputImageKey) filter.setValue(image, forKey: kCIInputImageKey)
let output: CIImage! = filter.outputImage?.cropped(to: request.sourceImage.extent) let output: CIImage! = filter.outputImage?.cropped(to: request.sourceImage.extent)
request.finish(with: output, context: nil) request.finish(with: output, context: nil)
} }
}
) )
#endif #endif
} }

View File

@ -353,7 +353,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
#endif #endif
if let video = _player?.currentItem, if let video = _player?.currentItem,
video == nil || video.status != AVPlayerItem.Status.readyToPlay { video.status != AVPlayerItem.Status.readyToPlay {
return return
} }
@ -386,7 +386,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
"playableDuration": RCTVideoUtils.calculatePlayableDuration(_player, withSource: _source), "playableDuration": RCTVideoUtils.calculatePlayableDuration(_player, withSource: _source),
"atValue": currentTime?.value ?? .zero, "atValue": currentTime?.value ?? .zero,
"currentPlaybackTime": NSNumber(value: Double(currentPlaybackTime?.timeIntervalSince1970 ?? 0 * 1000)).int64Value, "currentPlaybackTime": NSNumber(value: Double(currentPlaybackTime?.timeIntervalSince1970 ?? 0 * 1000)).int64Value,
"target": reactTag, "target": reactTag as Any,
"seekableDuration": RCTVideoUtils.calculateSeekableDuration(_player), "seekableDuration": RCTVideoUtils.calculateSeekableDuration(_player),
]) ])
} }
@ -418,12 +418,12 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
// Perform on next run loop, otherwise onVideoLoadStart is nil // Perform on next run loop, otherwise onVideoLoadStart is nil
onVideoLoadStart?([ onVideoLoadStart?([
"src": [ "src": [
"uri": _source?.uri ?? NSNull(), "uri": _source?.uri ?? NSNull() as Any,
"type": _source?.type ?? NSNull(), "type": _source?.type ?? NSNull(),
"isNetwork": NSNumber(value: _source?.isNetwork ?? false), "isNetwork": NSNumber(value: _source?.isNetwork ?? false),
], ],
"drm": source.drm?.json ?? NSNull(), "drm": source.drm?.json ?? NSNull(),
"target": reactTag, "target": reactTag as Any,
]) ])
if let uri = source.uri, uri.starts(with: "ph://") { if let uri = source.uri, uri.starts(with: "ph://") {
@ -491,7 +491,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
if _player == nil { if _player == nil {
_player = AVPlayer() _player = AVPlayer()
ReactNativeVideoManager.shared.onInstanceCreated(id: instanceId, player: _player) ReactNativeVideoManager.shared.onInstanceCreated(id: instanceId, player: _player as Any)
_player!.replaceCurrentItem(with: playerItem) _player!.replaceCurrentItem(with: playerItem)
@ -812,7 +812,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
self.setPaused(self._paused) self.setPaused(self._paused)
self.onVideoSeek?(["currentTime": NSNumber(value: Float(CMTimeGetSeconds(item.currentTime()))), self.onVideoSeek?(["currentTime": NSNumber(value: Float(CMTimeGetSeconds(item.currentTime()))),
"seekTime": time, "seekTime": time,
"target": self.reactTag]) "target": self.reactTag as Any])
} }
_pendingSeek = false _pendingSeek = false
@ -910,7 +910,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
func applyModifiers() { func applyModifiers() {
if let video = _player?.currentItem, if let video = _player?.currentItem,
video == nil || video.status != AVPlayerItem.Status.readyToPlay { video.status != AVPlayerItem.Status.readyToPlay {
return return
} }
if _muted { if _muted {
@ -1009,7 +1009,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
@objc @objc
func setFullscreen(_ fullscreen: Bool) { func setFullscreen(_ fullscreen: Bool) {
var alreadyFullscreenPresented = _presentingViewController?.presentedViewController != nil let alreadyFullscreenPresented = _presentingViewController?.presentedViewController != nil
if fullscreen && !_fullscreenPlayerPresented && _player != nil && !alreadyFullscreenPresented { if fullscreen && !_fullscreenPlayerPresented && _player != nil && !alreadyFullscreenPresented {
// Ensure player view controller is not null // Ensure player view controller is not null
// Controls will be displayed even if it is disabled in configuration // Controls will be displayed even if it is disabled in configuration
@ -1048,7 +1048,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
self._fullscreenPlayerPresented = fullscreen self._fullscreenPlayerPresented = fullscreen
self._playerViewController?.autorotate = self._fullscreenAutorotate self._playerViewController?.autorotate = self._fullscreenAutorotate
self.onVideoFullscreenPlayerDidPresent?(["target": self.reactTag]) self.onVideoFullscreenPlayerDidPresent?(["target": self.reactTag as Any])
}) })
} }
} }
@ -1312,7 +1312,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
_selectedAudioTrackCriteria = nil _selectedAudioTrackCriteria = nil
_presentingViewController = nil _presentingViewController = nil
ReactNativeVideoManager.shared.onInstanceRemoved(id: instanceId, player: _player) ReactNativeVideoManager.shared.onInstanceRemoved(id: instanceId, player: _player as Any)
_player = nil _player = nil
_resouceLoaderDelegate = nil _resouceLoaderDelegate = nil
_playerObserver.clearPlayer() _playerObserver.clearPlayer()
@ -1366,7 +1366,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
_isBuffering = false _isBuffering = false
} }
onReadyForDisplay?([ onReadyForDisplay?([
"target": reactTag, "target": reactTag as Any,
]) ])
} }
@ -1385,7 +1385,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
} }
onTimedMetadata?([ onTimedMetadata?([
"target": reactTag, "target": reactTag as Any,
"metadata": metadata, "metadata": metadata,
]) ])
} }
@ -1448,7 +1448,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
var orientation = "undefined" var orientation = "undefined"
let tracks = await RCTVideoAssetsUtils.getTracks(asset: _playerItem.asset, withMediaType: .video) let tracks = await RCTVideoAssetsUtils.getTracks(asset: _playerItem.asset, withMediaType: .video)
var presentationSize = _playerItem.presentationSize let presentationSize = _playerItem.presentationSize
if presentationSize.height != 0.0 { if presentationSize.height != 0.0 {
width = Float(presentationSize.width) width = Float(presentationSize.width)
height = Float(presentationSize.height) height = Float(presentationSize.height)
@ -1495,14 +1495,14 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
[ [
"error": [ "error": [
"code": NSNumber(value: (_playerItem.error! as NSError).code), "code": NSNumber(value: (_playerItem.error! as NSError).code),
"localizedDescription": _playerItem.error?.localizedDescription == nil ? "" : _playerItem.error?.localizedDescription, "localizedDescription": _playerItem.error?.localizedDescription == nil ? "" : _playerItem.error?.localizedDescription as Any,
"localizedFailureReason": ((_playerItem.error! as NSError).localizedFailureReason == nil ? "localizedFailureReason": ((_playerItem.error! as NSError).localizedFailureReason == nil ?
"" : (_playerItem.error! as NSError).localizedFailureReason) ?? "", "" : (_playerItem.error! as NSError).localizedFailureReason) ?? "",
"localizedRecoverySuggestion": ((_playerItem.error! as NSError).localizedRecoverySuggestion == nil ? "localizedRecoverySuggestion": ((_playerItem.error! as NSError).localizedRecoverySuggestion == nil ?
"" : (_playerItem.error! as NSError).localizedRecoverySuggestion) ?? "", "" : (_playerItem.error! as NSError).localizedRecoverySuggestion) ?? "",
"domain": (_playerItem.error as! NSError).domain, "domain": (_playerItem.error as! NSError).domain,
], ],
"target": reactTag, "target": reactTag as Any,
] ]
) )
} }
@ -1615,12 +1615,12 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
[ [
"error": [ "error": [
"code": NSNumber(value: (error as NSError).code), "code": NSNumber(value: (error as NSError).code),
"localizedDescription": error.localizedDescription ?? "", "localizedDescription": error.localizedDescription,
"localizedFailureReason": (error as NSError).localizedFailureReason ?? "", "localizedFailureReason": (error as NSError).localizedFailureReason ?? "",
"localizedRecoverySuggestion": (error as NSError).localizedRecoverySuggestion ?? "", "localizedRecoverySuggestion": (error as NSError).localizedRecoverySuggestion ?? "",
"domain": (error as NSError).domain, "domain": (error as NSError).domain,
], ],
"target": reactTag, "target": reactTag as Any,
] ]
) )
} }
@ -1667,7 +1667,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
guard let lastEvent = accessLog.events.last else { return } guard let lastEvent = accessLog.events.last else { return }
if lastEvent.indicatedBitrate != _lastBitrate { if lastEvent.indicatedBitrate != _lastBitrate {
_lastBitrate = lastEvent.indicatedBitrate _lastBitrate = lastEvent.indicatedBitrate
onVideoBandwidthUpdate?(["bitrate": _lastBitrate, "target": reactTag]) onVideoBandwidthUpdate?(["bitrate": _lastBitrate, "target": reactTag as Any])
} }
} }

View File

@ -1,7 +1,7 @@
import AVKit import AVKit
import Foundation import Foundation
protocol RCTVideoPlayerViewControllerDelegate: class { protocol RCTVideoPlayerViewControllerDelegate: AnyObject {
func videoPlayerViewControllerWillDismiss(playerViewController: AVPlayerViewController) func videoPlayerViewControllerWillDismiss(playerViewController: AVPlayerViewController)
func videoPlayerViewControllerDidDismiss(playerViewController: AVPlayerViewController) func videoPlayerViewControllerDidDismiss(playerViewController: AVPlayerViewController)
} }