diff --git a/ios/Plugin/SimpleSessionExporter.swift b/ios/Plugin/SimpleSessionExporter.swift index 41d3cc3..e2ab7df 100644 --- a/ios/Plugin/SimpleSessionExporter.swift +++ b/ios/Plugin/SimpleSessionExporter.swift @@ -29,6 +29,8 @@ open class SimpleSessionExporter: NSObject { self.asset = asset } + private var exportSession: AVAssetExportSession?; + public override init() { self.timeRange = CMTimeRange(start: CMTime.zero, end: CMTime.positiveInfinity) super.init() @@ -46,6 +48,12 @@ extension SimpleSessionExporter { /// Completion handler type for when an export finishes. public typealias CompletionHandler = (_ status: AVAssetExportSession.Status) -> Void + var progress: Float { + get { + self.exportSession?.progress ?? 0.0; + } + } + /// Initiates an export session. /// /// - Parameter completionHandler: Handler called when an export session completes. @@ -134,13 +142,16 @@ extension SimpleSessionExporter { export.videoComposition = videoComposition export.outputFileType = outputFileType export.outputURL = outputURL + self.exportSession = export export.exportAsynchronously { DispatchQueue.main.async { switch export.status { case .completed: + self.exportSession = nil completionHandler(.completed) default: + self.exportSession = nil print("Something went wrong during export.") print(export.error ?? "unknown error") completionHandler(.failed) diff --git a/ios/Plugin/VideoEditor.swift b/ios/Plugin/VideoEditor.swift index e75842f..153115b 100644 --- a/ios/Plugin/VideoEditor.swift +++ b/ios/Plugin/VideoEditor.swift @@ -42,8 +42,17 @@ import UIKit AVVideoHeightKey: NSNumber(integerLiteral: Int(targetVideoSize.height)), ] + let progressUpdater = DispatchQueue.main.schedule( + after: .init(.now()), + interval: .milliseconds(250), + { + progressHandler(exporter.progress) + } + ) + exporter.export( completionHandler: { status in + progressUpdater.cancel() switch status { case .completed: completionHandler(exporter.outputURL!)