Skip to content

Instantly share code, notes, and snippets.

@agammahajan1
Created September 6, 2020 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agammahajan1/0b262508db828a997bbff6612d25d79c to your computer and use it in GitHub Desktop.
Save agammahajan1/0b262508db828a997bbff6612d25d79c to your computer and use it in GitHub Desktop.
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,
eventName: NewRelicEventName.videoCacheHit,
attributes: [NewRelicAttributeKey.videoSize: fileURL.fileSizeString])
return fileURL
} else {
return nil
}
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment