Skip to content

Commit

Permalink
chore: apply code review
Browse files Browse the repository at this point in the history
  • Loading branch information
KrzysztofMoch committed Nov 17, 2023
1 parent 7b9ee71 commit 74d8f14
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions ios/Video/Features/RCTVideoUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand All @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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.
Expand All @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 74d8f14

Please sign in to comment.