Open notsag-dev opened 9 months ago
Having the same issue. Solving it in the following way:
[!NOTE] This is not exactly how I use it. I'm using a class where I have a stream controller and a completer where the completer is completed once compression is finished, and the stream gets continuous progress updates.
int? percentage = 0;
final subscription =
vc.VideoCompress.compressProgress$.subscribe((progress) {
percentage = progress.toInt();
});
final vc.MediaInfo? mediaInfo = await vc.VideoCompress.compressVideo(
file.path,
includeAudio: true,
);
subscription.unsubscribe();
canceled = false;
failed = false;
File? compressedFile;
if (mediaInfo != null && mediaInfo.file != null) {
if (mediaInfo.isCancel == true) {
canceled = true;
} else {
compressedFile = mediaInfo.file!;
percentage = 100;
}
} else {
failed = true;
}
For a workaround, see https://github.com/jonataslaw/VideoCompress/issues/259#issuecomment-2208455491.
Issue:
This line seems to be the issue: https://github.com/jonataslaw/VideoCompress/blob/e06673f1fd4dbb82bfd4037411a3b8cfdf9190a8/ios/Classes/SwiftVideoCompressPlugin.swift#L227
The timer that updates the progress every 0.1
seconds may be invalidated before the 100% progress can be propagated.
Proposal:
I'd suggest invalidating the timer inside the updateProgress
func once the progress has reached 100% or stopCommand
is true
:
@objc private func updateProgress(timer: Timer) {
let asset = timer.userInfo as! AVAssetExportSession
guard !stopCommand && asset.progress < 1.0 else {
timer.invalidate()
return
}
channel.invokeMethod("updateProgress", arguments: "\(String(describing: asset.progress * 100))")
}
Any update on if this fix will be implemented into 3.1.4?
I'm subscribing to the progress of the compression to give visual feedback to the user. On Android the progress goes until a 100 but for iOS it seems to stop right before getting to 100, it seems it just misses the last event because it gets super close. Anyone else seeing this issue?
Thanks.