From 74d8f143cdcaf7b66d509214e85cb794b22a1e5d Mon Sep 17 00:00:00 2001 From: Krzysztof Moch Date: Mon, 6 Nov 2023 10:14:35 +0100 Subject: [PATCH] chore: apply code review --- ios/Video/Features/RCTVideoUtils.swift | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/ios/Video/Features/RCTVideoUtils.swift b/ios/Video/Features/RCTVideoUtils.swift index f92d7a61a8..3e0ef3bb36 100644 --- a/ios/Video/Features/RCTVideoUtils.swift +++ b/ios/Video/Features/RCTVideoUtils.swift @@ -45,7 +45,7 @@ enum RCTVideoUtils { return 0 } - + static func urlFilePath(filepath:NSString!, searchPath:FileManager.SearchPathDirectory) -> NSURL! { if filepath.contains("file://") { return NSURL(string: filepath as String) @@ -100,7 +100,7 @@ enum RCTVideoUtils { guard let player = player else { return [] } - + let audioTracks:NSMutableArray! = NSMutableArray() let group = player.currentItem?.asset.mediaSelectionGroup(forMediaCharacteristic: .audible) for i in 0..<(group?.options.count ?? 0) { @@ -111,9 +111,9 @@ enum RCTVideoUtils { title = value as! String } let language:String! = currentOption?.extendedLanguageTag ?? "" - + let selectedOption: AVMediaSelectionOption? = player.currentItem?.currentMediaSelection.selectedMediaOption(in: group!) - + let audioTrack = [ "index": NSNumber(value: i), "title": title, @@ -129,7 +129,7 @@ enum RCTVideoUtils { guard let player = player else { return [] } - + // if streaming video, we extract the text tracks var textTracks:[TextTrack] = [] let group = player.currentItem?.asset.mediaSelectionGroup(forMediaCharacteristic: .legible) @@ -165,18 +165,18 @@ enum RCTVideoUtils { } return nil } - + static func replaceURLScheme(url: URL, scheme: String?) -> URL? { var urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: false) urlComponents?.scheme = scheme - + return urlComponents?.url } - + static func extractDataFromCustomSchemeUrl(from url: URL, scheme: String) -> Data? { guard url.scheme == scheme, let adoptURL = RCTVideoUtils.replaceURLScheme(url:url, scheme: nil) else { return nil } - + return Data(base64Encoded: adoptURL.absoluteString) } @@ -242,7 +242,7 @@ enum RCTVideoUtils { return validTextTracks } - + /* * Create an useless / almost empty VTT file in the list with available tracks. This track gets selected when you give type: "disabled" as the selectedTextTrack * This is needed because there is a bug where sideloaded texttracks cannot be disabled in the AVPlayer. Loading this VTT file instead solves that problem. @@ -255,7 +255,7 @@ enum RCTVideoUtils { if !fileManager.fileExists(atPath: filePath) { let stringToWrite = "WEBVTT\n\n1\n99:59:59.000 --> 99:59:59.001\n." - + do { try stringToWrite.write(to: URL(fileURLWithPath: filePath), atomically: true, encoding: String.Encoding.utf8) } catch { @@ -319,7 +319,7 @@ enum RCTVideoUtils { static func createMetadataItems(for mapping: [AVMetadataIdentifier: Any]) -> [AVMetadataItem] { return mapping.compactMap { createMetadataItem(for:$0, value:$1) } } - + static func createMetadataItem(for identifier: AVMetadataIdentifier, value: Any) -> AVMetadataItem { let item = AVMutableMetadataItem()