Skip to content

Commit

Permalink
chore(ios): remove some warnings (#4159)
Browse files Browse the repository at this point in the history
  • Loading branch information
freeboub authored Sep 13, 2024
1 parent 2c1fc96 commit 7118ba6
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ class VideoPluginSample: NSObject, RNVPlugin {
* custom functions to be able to track AVPlayer state change
*/
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>) {
NSLog("plugin: handlePlayerItemStatusChange \(playerItem.status)")
}

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 {
_playerItemStatusObserver?.invalidate()
return
Expand Down
7 changes: 3 additions & 4 deletions ios/Video/Features/RCTPlayerObserver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,9 @@ class RCTPlayerObserver: NSObject, AVPlayerItemMetadataOutputPushDelegate, AVPla

/* Cancels the previously registered time observer. */
func removePlayerTimeObserver() {
if _timeObserver != nil {
player?.removeTimeObserver(_timeObserver)
_timeObserver = nil
}
guard let timeObserver = _timeObserver else { return }
player?.removeTimeObserver(timeObserver)
_timeObserver = nil
}

func addTimeObserverIfNotSet() {
Expand Down
8 changes: 4 additions & 4 deletions ios/Video/Features/RCTResourceLoaderDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class RCTResourceLoaderDelegate: NSObject, AVAssetResourceLoaderDelegate, URLSes
func setLicenseResult(_ license: String!, _ licenseUrl: String!) {
// Check if the loading request exists in _loadingRequests based on licenseUrl
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
}

Expand Down Expand Up @@ -87,12 +87,12 @@ class RCTResourceLoaderDelegate: NSObject, AVAssetResourceLoaderDelegate, URLSes
_onVideoError?([
"error": [
"code": NSNumber(value: error.code),
"localizedDescription": error.localizedDescription ?? "",
"localizedDescription": error.localizedDescription,
"localizedFailureReason": error.localizedFailureReason ?? "",
"localizedRecoverySuggestion": error.localizedRecoverySuggestion ?? "",
"domain": error.domain,
],
"target": _reactTag,
"target": _reactTag as Any,
])

return false
Expand Down Expand Up @@ -158,7 +158,7 @@ class RCTResourceLoaderDelegate: NSObject, AVAssetResourceLoaderDelegate, URLSes
"loadedLicenseUrl": loadingRequest.request.url?.absoluteString ?? "",
"contentId": contentId ?? "",
"spcBase64": spcData.base64EncodedString(options: []),
"target": self._reactTag])
"target": self._reactTag as Any])
} else {
let data = try await RCTVideoDRM.handleInternalGetLicense(
loadingRequest: loadingRequest,
Expand Down
4 changes: 1 addition & 3 deletions ios/Video/Features/RCTVideoSave.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,11 @@ enum RCTVideoSave {

static func ensureDirExists(withPath path: String?) -> Bool {
var isDir: ObjCBool = false
var error: Error?
let exists = FileManager.default.fileExists(atPath: path ?? "", isDirectory: &isDir)
if !(exists && isDir.boolValue) {
do {
try FileManager.default.createDirectory(atPath: path ?? "", withIntermediateDirectories: true, attributes: nil)
} catch {}
if error != nil {
} catch {
return false
}
}
Expand Down
31 changes: 11 additions & 20 deletions ios/Video/Features/RCTVideoUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,11 @@ enum RCTVideoUtils {
title = value as! String
}
let language: String! = currentOption?.extendedLanguageTag ?? ""
let selectedOpt = player.currentItem?.currentMediaSelection
let selectedOption: AVMediaSelectionOption? = player.currentItem?.currentMediaSelection.selectedMediaOption(in: group!)
let textTrack = TextTrack([
"index": NSNumber(value: i),
"title": title,
"language": language,
"language": language as Any,
"selected": currentOption?.displayName == selectedOption?.displayName,
])
textTracks.append(textTrack)
Expand Down Expand Up @@ -375,8 +374,8 @@ enum RCTVideoUtils {
assetOptions.setObject(headers, forKey: "AVURLAssetHTTPHeaderFieldsKey" as NSCopying)
}
let cookies: [AnyObject]! = HTTPCookieStorage.shared.cookies
assetOptions.setObject(cookies, forKey: AVURLAssetHTTPCookiesKey as NSCopying)
asset = AVURLAsset(url: url!, options: assetOptions as! [String: Any])
assetOptions.setObject(cookies as Any, forKey: AVURLAssetHTTPCookiesKey as NSCopying)
asset = AVURLAsset(url: url!, options: assetOptions as? [String: Any])
} else {
asset = AVURLAsset(url: url!)
}
Expand Down Expand Up @@ -431,29 +430,21 @@ enum RCTVideoUtils {
return try? await AVVideoComposition.videoComposition(
with: asset,
applyingCIFiltersWithHandler: { (request: AVAsynchronousCIImageFilteringRequest) in
if filter == nil {
request.finish(with: request.sourceImage, context: nil)
} else {
let image: CIImage! = request.sourceImage.clampedToExtent()
filter.setValue(image, forKey: kCIInputImageKey)
let output: CIImage! = filter.outputImage?.cropped(to: request.sourceImage.extent)
request.finish(with: output, context: nil)
}
let image: CIImage! = request.sourceImage.clampedToExtent()
filter.setValue(image, forKey: kCIInputImageKey)
let output: CIImage! = filter.outputImage?.cropped(to: request.sourceImage.extent)
request.finish(with: output, context: nil)
}
)
} else {
#if !os(visionOS)
return AVVideoComposition(
asset: asset,
applyingCIFiltersWithHandler: { (request: AVAsynchronousCIImageFilteringRequest) in
if filter == nil {
request.finish(with: request.sourceImage, context: nil)
} else {
let image: CIImage! = request.sourceImage.clampedToExtent()
filter.setValue(image, forKey: kCIInputImageKey)
let output: CIImage! = filter.outputImage?.cropped(to: request.sourceImage.extent)
request.finish(with: output, context: nil)
}
let image: CIImage! = request.sourceImage.clampedToExtent()
filter.setValue(image, forKey: kCIInputImageKey)
let output: CIImage! = filter.outputImage?.cropped(to: request.sourceImage.extent)
request.finish(with: output, context: nil)
}
)
#endif
Expand Down
36 changes: 18 additions & 18 deletions ios/Video/RCTVideo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
#endif

if let video = _player?.currentItem,
video == nil || video.status != AVPlayerItem.Status.readyToPlay {
video.status != AVPlayerItem.Status.readyToPlay {
return
}

Expand Down Expand Up @@ -386,7 +386,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
"playableDuration": RCTVideoUtils.calculatePlayableDuration(_player, withSource: _source),
"atValue": currentTime?.value ?? .zero,
"currentPlaybackTime": NSNumber(value: Double(currentPlaybackTime?.timeIntervalSince1970 ?? 0 * 1000)).int64Value,
"target": reactTag,
"target": reactTag as Any,
"seekableDuration": RCTVideoUtils.calculateSeekableDuration(_player),
])
}
Expand Down Expand Up @@ -418,12 +418,12 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
// Perform on next run loop, otherwise onVideoLoadStart is nil
onVideoLoadStart?([
"src": [
"uri": _source?.uri ?? NSNull(),
"uri": _source?.uri ?? NSNull() as Any,
"type": _source?.type ?? NSNull(),
"isNetwork": NSNumber(value: _source?.isNetwork ?? false),
],
"drm": source.drm?.json ?? NSNull(),
"target": reactTag,
"target": reactTag as Any,
])

if let uri = source.uri, uri.starts(with: "ph://") {
Expand Down Expand Up @@ -491,7 +491,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH

if _player == nil {
_player = AVPlayer()
ReactNativeVideoManager.shared.onInstanceCreated(id: instanceId, player: _player)
ReactNativeVideoManager.shared.onInstanceCreated(id: instanceId, player: _player as Any)

_player!.replaceCurrentItem(with: playerItem)

Expand Down Expand Up @@ -812,7 +812,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
self.setPaused(self._paused)
self.onVideoSeek?(["currentTime": NSNumber(value: Float(CMTimeGetSeconds(item.currentTime()))),
"seekTime": time,
"target": self.reactTag])
"target": self.reactTag as Any])
}

_pendingSeek = false
Expand Down Expand Up @@ -910,7 +910,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH

func applyModifiers() {
if let video = _player?.currentItem,
video == nil || video.status != AVPlayerItem.Status.readyToPlay {
video.status != AVPlayerItem.Status.readyToPlay {
return
}
if _muted {
Expand Down Expand Up @@ -1009,7 +1009,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH

@objc
func setFullscreen(_ fullscreen: Bool) {
var alreadyFullscreenPresented = _presentingViewController?.presentedViewController != nil
let alreadyFullscreenPresented = _presentingViewController?.presentedViewController != nil
if fullscreen && !_fullscreenPlayerPresented && _player != nil && !alreadyFullscreenPresented {
// Ensure player view controller is not null
// Controls will be displayed even if it is disabled in configuration
Expand Down Expand Up @@ -1048,7 +1048,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
self._fullscreenPlayerPresented = fullscreen
self._playerViewController?.autorotate = self._fullscreenAutorotate

self.onVideoFullscreenPlayerDidPresent?(["target": self.reactTag])
self.onVideoFullscreenPlayerDidPresent?(["target": self.reactTag as Any])
})
}
}
Expand Down Expand Up @@ -1312,7 +1312,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
_selectedAudioTrackCriteria = nil
_presentingViewController = nil

ReactNativeVideoManager.shared.onInstanceRemoved(id: instanceId, player: _player)
ReactNativeVideoManager.shared.onInstanceRemoved(id: instanceId, player: _player as Any)
_player = nil
_resouceLoaderDelegate = nil
_playerObserver.clearPlayer()
Expand Down Expand Up @@ -1366,7 +1366,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
_isBuffering = false
}
onReadyForDisplay?([
"target": reactTag,
"target": reactTag as Any,
])
}

Expand All @@ -1385,7 +1385,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
}

onTimedMetadata?([
"target": reactTag,
"target": reactTag as Any,
"metadata": metadata,
])
}
Expand Down Expand Up @@ -1448,7 +1448,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
var orientation = "undefined"

let tracks = await RCTVideoAssetsUtils.getTracks(asset: _playerItem.asset, withMediaType: .video)
var presentationSize = _playerItem.presentationSize
let presentationSize = _playerItem.presentationSize
if presentationSize.height != 0.0 {
width = Float(presentationSize.width)
height = Float(presentationSize.height)
Expand Down Expand Up @@ -1495,14 +1495,14 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
[
"error": [
"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 ?
"" : (_playerItem.error! as NSError).localizedFailureReason) ?? "",
"localizedRecoverySuggestion": ((_playerItem.error! as NSError).localizedRecoverySuggestion == nil ?
"" : (_playerItem.error! as NSError).localizedRecoverySuggestion) ?? "",
"domain": (_playerItem.error as! NSError).domain,
],
"target": reactTag,
"target": reactTag as Any,
]
)
}
Expand Down Expand Up @@ -1615,12 +1615,12 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
[
"error": [
"code": NSNumber(value: (error as NSError).code),
"localizedDescription": error.localizedDescription ?? "",
"localizedDescription": error.localizedDescription,
"localizedFailureReason": (error as NSError).localizedFailureReason ?? "",
"localizedRecoverySuggestion": (error as NSError).localizedRecoverySuggestion ?? "",
"domain": (error as NSError).domain,
],
"target": reactTag,
"target": reactTag as Any,
]
)
}
Expand Down Expand Up @@ -1667,7 +1667,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
guard let lastEvent = accessLog.events.last else { return }
if lastEvent.indicatedBitrate != _lastBitrate {
_lastBitrate = lastEvent.indicatedBitrate
onVideoBandwidthUpdate?(["bitrate": _lastBitrate, "target": reactTag])
onVideoBandwidthUpdate?(["bitrate": _lastBitrate, "target": reactTag as Any])
}
}

Expand Down
2 changes: 1 addition & 1 deletion ios/Video/RCTVideoPlayerViewControllerDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import AVKit
import Foundation

protocol RCTVideoPlayerViewControllerDelegate: class {
protocol RCTVideoPlayerViewControllerDelegate: AnyObject {
func videoPlayerViewControllerWillDismiss(playerViewController: AVPlayerViewController)
func videoPlayerViewControllerDidDismiss(playerViewController: AVPlayerViewController)
}

0 comments on commit 7118ba6

Please sign in to comment.