starkdmi/MediaToolSwift

'progress' property of 'CompressionTask' is not giving progress information.

Closed this issue · 2 comments

Thank you for this wonderful tool to solve video conversion problem.

I was using the tool with older version since few months and now updated to 1.2.0. Changes are done in my code as per new method signatures and properties. As per the latest release notes, .progress() state is removed so using progress property of CompressionTask.
(1) When I try to get the progress status when conversion is going on, it does not give any info about the progress. Here is my code for better understanding.

 Task {
            let task = await VideoTool.convert(source: source, destination: destination, fileType: .mp4, videoSettings: videoSettings, overwrite: true, callback: { [weak self] state in
                guard let self = self else { return }
                switch state {
                case .started:
                    debugLog("Started")
                case .completed(let mediaInfo):
                    debugLog("Done: \(mediaInfo.url.absoluteString)")
                case .failed(let error):
                    if let error = error as? MediaToolSwift.CompressionError {
                        debugLog("Error: \(error.description)")
                    } else {
                        debugLog("Error: \(error.localizedDescription)")
                    }
                case .cancelled:
                    debugLog("Cancelled")
                }
            })
            
            _ = task.progress.observe(\.fractionCompleted) { progress, _ in
                debugLog("Progress: \(progress.fractionCompleted)")
            }
        }
    }

(2) I get below warning at the first line of code where task is initialised.
"Passing argument of non-sendable type '[AVMetadataItem]' outside of main actor-isolated context may introduce data races"

@vishalgabani, according to the first issue I guess you just need to store it correctly:

// Store variable somewhere
var progressObservation: NSKeyValueObservation?

// Your code
progressObservation = task.progress.observe(\.fractionCompleted) { progress, _ in
    debugLog("Progress: \(progress.fractionCompleted)")
}

You can also attach task.progress to a ProgressView.

"Passing argument of non-sendable type '[AVMetadataItem]' outside of main actor-isolated context may introduce data races"

Could be an error in Swift 6, but I think to get rid of async/await by then as it's actually used just to capture all possible errors before starting the compression.