This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import AVFoundation | |
class VideoTrimmer { | |
typealias TrimCompletion = (Error?) -> () | |
typealias TrimPoints = [(CMTime, CMTime)] | |
func verifyPresetForAsset(preset: String, asset: AVAsset) -> Bool { | |
let compatiblePresets = AVAssetExportSession.exportPresets(compatibleWith: asset) | |
let filteredPresets = compatiblePresets.filter { $0 == preset } | |
return filteredPresets.count > 0 || preset == AVAssetExportPresetPassthrough |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIDeviceOrientation { | |
var imageOrientation: UIImage.Orientation { | |
switch UIDevice.current.orientation { | |
case .landscapeLeft: | |
return UIImage.Orientation.right | |
case .landscapeRight: | |
return UIImage.Orientation.left | |
case .portrait: | |
return UIImage.Orientation.up |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension ViewController { | |
func creatingAnAssetObject(asset: AVAsset) { | |
let anAsset = asset | |
// anAsset.cancelLoading() | |
let keys = ["duration"] | |
anAsset.loadValuesAsynchronously(forKeys: keys) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension CGAffineTransform { | |
// Check the video track's preferred transform to determine if it was recorded in portrait mode. | |
var isPortrait: Bool { | |
if self.a == 0 && self.d == 0 && (self.b == 1.0 || self.b == -1.0) && (self.c == 1.0 || self.c == -1.0) { | |
return true | |
} | |
return false | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var isSeekInProgress = false | |
var chasingTime = CMTime.zero | |
func seekActually(time: CMTime) { | |
isSeekInProgress = true | |
playerView?.player.seek(to: time, toleranceBefore: CMTime.zero, toleranceAfter: CMTime.zero) { success in | |
if time == self.chasingTime { | |
self.isSeekInProgress = false | |
} else { | |
self.trySeekToChaseTime() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@propertyWrapper | |
struct UserDefault<T> { | |
let key: String | |
let value: T | |
init(key: String, default value: T) { | |
self.key = key | |
self.value = value | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension HomeViewController: UIPageViewControllerDataSource { | |
func pageViewController(_ pageViewController: UIPageViewController, | |
viewControllerBefore viewController: UIViewController) -> UIViewController? { | |
guard let index = mainViewControllers.firstIndex(of: viewController) else { return nil } | |
let prevIndex = index - 1 | |
guard prevIndex >= 0, prevIndex < mainViewControllers.count else { return nil } | |
return mainViewControllers[prevIndex] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tableView.tableFooterView = UIView(frame: .zero) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension CGAffineTransform { | |
// Check the video track's preferred transform to determine if it was recorded in portrait mode. | |
var isPortrait: Bool { | |
if self.a == 0 && self.d == 0 && (self.b == 1.0 || self.b == -1.0) && (self.c == 1.0 || self.c == -1.0) { | |
return true | |
} | |
return false | |
} | |
} |