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
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
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 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
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
func removeVideoIfMaxNumberOfVideosReached() { | |
if popupVideosDict.count >= maxVideosAllowed { | |
// remove the least recently used video | |
let sortedDict = popupVideosDict.keysSortedByValue { (v1, v2) -> Bool in | |
v1.timeStamp < v2.timeStamp | |
} | |
guard let videoId = sortedDict.first else { | |
return | |
} | |
popupVideosDict.removeValue(forKey: videoId) |
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
static func findCachedVideoURL(forVideoId id: String) -> URL? { | |
let nsDocumentDirectory = FileManager.SearchPathDirectory.documentDirectory | |
let nsUserDomainMask = FileManager.SearchPathDomainMask.userDomainMask | |
let paths = NSSearchPathForDirectoriesInDomains(nsDocumentDirectory, nsUserDomainMask, true) | |
if let dirPath = paths.first { | |
let fileURL = URL(fileURLWithPath: dirPath).appendingPathComponent(folderPath).appendingPathComponent(id + ".mp4") | |
let filePath = fileURL.path | |
let fileManager = FileManager.default | |
if fileManager.fileExists(atPath: filePath) { | |
NewRelicService.sendCustomEvent(with: NewRelicEventType.statusCodes, |
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 URL { | |
var attributes: [FileAttributeKey : Any]? { | |
do { | |
return try FileManager.default.attributesOfItem(atPath: path) | |
} catch let error as NSError { | |
print("FileAttribute error: \(error)") | |
} | |
return nil | |
} |
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
cell.isAccessibilityElement = true | |
cell.accessibilityLabel = restaurantName + rating + offer |