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
func isStorageAvailable() -> Bool { | |
let fileURL = URL(fileURLWithPath: NSHomeDirectory() as String) | |
do { | |
let values = try fileURL.resourceValues(forKeys: [.volumeAvailableCapacityForImportantUsageKey, .volumeTotalCapacityKey]) | |
guard let totalSpace = values.volumeTotalCapacity, | |
let freeSpace = values.volumeAvailableCapacityForImportantUsage else { | |
return false | |
} | |
if freeSpace > minimumSpaceRequired { | |
return true |
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
if let cacheUrl = FindCachedVideoURL(forVideoId: videoId) { | |
let cacheAsset = AVURLAsset(url: cacheUrl) | |
asynchronouslyLoadURLAssets(cacheAsset) | |
} | |
else { | |
asynchronouslyLoadURLAssets(newAsset) | |
} |
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
let exporter = AVAssetExportSession(asset: avUrlAsset, presetName: AVAssetExportPresetHighestQuality) | |
exporter?.outputURL = outputURL | |
exporter?.outputFileType = AVFileType.mp4 | |
exporter?.exportAsynchronously(completionHandler: { | |
print(exporter?.status.rawValue) | |
print(exporter?.error) | |
}) |
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
func asynchronouslyLoadURLAssets(_ newAsset: AVURLAsset) { | |
DispatchQueue.main.async { | |
newAsset.loadValuesAsynchronously(forKeys: self.assetKeysRequiredToPlay) { | |
for key in self.assetKeysRequiredToPlay { | |
var error: NSError? | |
if newAsset.statusOfValue(forKey: key, error: &error) == .failed { | |
self.delegate?.playerDidFailToPlay(message: "Can't use this AVAsset because one of it's keys failed to load") | |
return | |
} | |
} |
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
@objc func didTapSnap(_ sender: UITapGestureRecognizer) { | |
let touchLocation = sender.location(ofTouch: 0, in: view) | |
if touchLocation.x < view.frame.width/2 { | |
changePlayer(forward: false) | |
} | |
else { | |
fillupLastPlayedSnap() | |
changePlayer(forward: true) | |
} | |
} |
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
func addPlayer(player: AVPlayer) { | |
player.currentItem?.seek(to: CMTime.zero, completionHandler: nil) | |
playerViewModel?.player = player | |
playerView.playerLayer.player = player | |
} |
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
let videoURL = URL(string: "Sample-Video-Url") | |
let player = AVPlayer(url: videoURL!) | |
let playerLayer = AVPlayerLayer(player: player) | |
playerLayer.frame = self.view.bounds | |
self.view.layer.addSublayer(playerLayer) | |
player.play() |
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
let videoURL = URL(string: "Sample-Video-Url") | |
let player = AVPlayer(url: videoURL!) | |
let playerViewController = AVPlayerViewController() | |
playerViewController.player = player | |
self.present(playerViewController, animated: true) { | |
playerViewController.player.play() | |
} |
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
private let colorArray = ["FBDA75", "FFCCAC", "FFD4E4", "DCDEF9"] | |
private let imageArray = ["image-1", "image-2", "image-3", "image-4"] | |
private var timer: Timer? | |
private var iconsInterval: Int = 0 | |
// for image animation | |
private var imageView1: UIImageView! | |
private var imageView2: UIImageView! | |
private var imageViewChangeflag = 1 | |
private var initalPosition: CGPoint! |
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
private func getSpringAnimation(withInitialPostion initialPos: CGPoint, finalPos: CGPoint) -> CASpringAnimation { | |
let basicAnimation = CASpringAnimation(keyPath: "position") | |
basicAnimation.fromValue = NSValue(cgPoint: initialPos) | |
basicAnimation.toValue = NSValue(cgPoint: finalPos) | |
basicAnimation.duration = basicAnimation.settlingDuration | |
basicAnimation.damping = 14 | |
basicAnimation.initialVelocity = 5 | |
basicAnimation.isRemovedOnCompletion = false | |
basicAnimation.fillMode = CAMediaTimingFillMode.forwards | |
return basicAnimation |