Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented a common typealias to replace the completion handlers for video operations #83

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Classes/Celestial/Celestial.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ extension Celestial: CelestialVideoCachingProtocol {
VideoCache.shared.store(videoData, with: sourceURLString.convertURLToUniqueFileName())
}

public func storeDownloadedVideoToFileCache(_ temporaryFileURL: URL, withSourceURL sourceURL: URL, videoExportQuality: Celestial.VideoExportQuality, completion: @escaping (URL?, Error?) -> ()) {
public func storeDownloadedVideoToFileCache(_ temporaryFileURL: URL, withSourceURL sourceURL: URL, videoExportQuality: Celestial.VideoExportQuality, completion: @escaping MediaAssetCompletionHandler) {
FileStorageManager.shared.cacheVideo(withSourceURL: sourceURL, intermediateTemporaryFileURL: temporaryFileURL, videoExportQuality: videoExportQuality) { [weak self] (cachedVideoURL, error) in

let resourceIdentifier = CachedResourceIdentifier(sourceURL: sourceURL,
Expand All @@ -91,7 +91,7 @@ extension Celestial: CelestialVideoCachingProtocol {
}
}

public func decreaseVideoQuality(intermediateFileURL: URL, withSourceURL sourceURL: URL, toQuality videoExportQuality: Celestial.VideoExportQuality, completion: @escaping (_ outputURL: URL?, _ error: Error?) -> ()) {
public func decreaseVideoQuality(intermediateFileURL: URL, withSourceURL sourceURL: URL, toQuality videoExportQuality: Celestial.VideoExportQuality, completion: @escaping MediaAssetCompletionHandler) {
FileStorageManager.shared.decreaseVideoQuality(intermediateFileURL: intermediateFileURL, withSourceURL: sourceURL, toQuality: videoExportQuality, completion: completion)
}

Expand Down
2 changes: 1 addition & 1 deletion Classes/DownloadManager/AssetExportManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ internal class AssetExportManager: NSObject {

// MARK: - Functions

internal static func exportVideo(fromIntermediateFileURL intermediateTemporaryFileURL: URL, outputURL: URL, videoExportQuality: Celestial.VideoExportQuality, completion: @escaping (URL?, Error?) -> ()) {
internal static func exportVideo(fromIntermediateFileURL intermediateTemporaryFileURL: URL, outputURL: URL, videoExportQuality: Celestial.VideoExportQuality, completion: @escaping MediaAssetCompletionHandler) {
let assetKeys: [URLVideoPlayerView.LoadableAssetKeys] = [.tracks, .exportable]
DispatchQueue.global(qos: .utility).async {
AVURLAsset.prepareUsableAsset(withAssetKeys: assetKeys, inputURL: intermediateTemporaryFileURL) { (exportableAsset, error) in
Expand Down
6 changes: 3 additions & 3 deletions Classes/DownloadManager/FileStorageManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ internal protocol FileStorageMangerProtocol {
func cacheVideo(withSourceURL sourceURL: URL,
intermediateTemporaryFileURL: URL,
videoExportQuality: Celestial.VideoExportQuality,
completion: @escaping (_ cachedVideoURL: URL?, _ error: Error?) -> ())
completion: @escaping MediaAssetCompletionHandler)

/**
Resizes the image with a given point size and caches it
Expand Down Expand Up @@ -326,7 +326,7 @@ internal class FileStorageManager: NSObject, FileStorageMangerProtocol {
internal func cacheVideo(withSourceURL sourceURL: URL,
intermediateTemporaryFileURL: URL,
videoExportQuality: Celestial.VideoExportQuality,
completion: @escaping (_ cachedVideoURL: URL?, _ error: Error?) -> ()) {
completion: @escaping MediaAssetCompletionHandler) {

let outputURL = constructFormattedURL(from: sourceURL,
expectedDirectoryURL: directoryManager.videosDirectoryURL,
Expand Down Expand Up @@ -364,7 +364,7 @@ internal class FileStorageManager: NSObject, FileStorageMangerProtocol {
}
}

internal func decreaseVideoQuality(intermediateFileURL: URL, withSourceURL sourceURL: URL, toQuality videoExportQuality: Celestial.VideoExportQuality, completion: @escaping (_ outputURL: URL?, _ error: Error?) -> ()) {
internal func decreaseVideoQuality(intermediateFileURL: URL, withSourceURL sourceURL: URL, toQuality videoExportQuality: Celestial.VideoExportQuality, completion: @escaping MediaAssetCompletionHandler) {
let outputURL = constructFormattedURL(from: sourceURL,
expectedDirectoryURL: directoryManager.videosDirectoryURL,
size: nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ enum CLSError: Error {





/// Completion block returns an optional URL if the operation has completed successfully, or an error if otherwise
public typealias MediaAssetCompletionHandler = (URL?, Error?) -> ()



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ internal protocol CelestialVideoCachingProtocol: class {
```

*/
func storeDownloadedVideoToFileCache(_ temporaryFileURL: URL, withSourceURL sourceURL: URL, videoExportQuality: Celestial.VideoExportQuality, completion: @escaping (URL?, Error?) -> ())
func storeDownloadedVideoToFileCache(_ temporaryFileURL: URL, withSourceURL sourceURL: URL, videoExportQuality: Celestial.VideoExportQuality, completion: @escaping MediaAssetCompletionHandler)



Expand Down