Skip to content

Commit

Permalink
Merge pull request #11 from 1stphorm/ios-progress-update-handler
Browse files Browse the repository at this point in the history
Enable progress reporting for ios.
  • Loading branch information
dragermrb authored Aug 7, 2023
2 parents 2c55205 + ff23263 commit 980df2b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
11 changes: 11 additions & 0 deletions ios/Plugin/SimpleSessionExporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions ios/Plugin/VideoEditor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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!)
Expand Down

0 comments on commit 980df2b

Please sign in to comment.