Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ class VideoCompressPlugin : MethodCallHandler, FlutterPlugin {
val path = call.argument<String>("path")!!
val quality = call.argument<Int>("quality")!!
val deleteOrigin = call.argument<Boolean>("deleteOrigin")!!
val startTime = call.argument<Int>("startTime")
val duration = call.argument<Int>("duration")
val startTime = call.argument<Number>("startTime")
val duration = call.argument<Number>("duration")
val includeAudio = call.argument<Boolean>("includeAudio") ?: true
val frameRate = if (call.argument<Int>("frameRate")==null) 30 else call.argument<Int>("frameRate")

Expand Down Expand Up @@ -129,7 +129,7 @@ class VideoCompressPlugin : MethodCallHandler, FlutterPlugin {

val dataSource = if (startTime != null || duration != null){
val source = UriDataSource(context, Uri.parse(path))
TrimDataSource(source, (1000 * 1000 * (startTime ?: 0)).toLong(), (1000 * 1000 * (duration ?: 0)).toLong())
TrimDataSource(source, (1000 * 1000 * (startTime ?: 0).toDouble()).toLong(), (1000 * 1000 * (duration ?: 0).toDouble()).toLong())
}else{
UriDataSource(context, Uri.parse(path))
}
Expand Down
21 changes: 6 additions & 15 deletions ios/Classes/SwiftVideoCompressPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public class SwiftVideoCompressPlugin: NSObject, FlutterPlugin {
exporter.videoComposition = videoComposition
}

if !isIncludeAudio {
if isIncludeAudio {
exporter.timeRange = timeRange
}

Expand All @@ -214,28 +214,19 @@ public class SwiftVideoCompressPlugin: NSObject, FlutterPlugin {
let timer = Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(self.updateProgress),
userInfo: exporter, repeats: true)

stopCommand = false
exporter.exportAsynchronously(completionHandler: {
timer.invalidate()
self.exporter = nil
if(self.stopCommand) {
timer.invalidate()
self.stopCommand = false
var json = self.getMediaInfoJson(path)
json["isCancel"] = true
let jsonString = Utility.keyValueToJson(json)
return result(jsonString)
}
if deleteOrigin {
timer.invalidate()
let fileManager = FileManager.default
do {
if fileManager.fileExists(atPath: path) {
try fileManager.removeItem(atPath: path)
}
self.exporter = nil
self.stopCommand = false
}
catch let error as NSError {
print(error)
}
Utility.deleteFile(path)
}
var json = self.getMediaInfoJson(compressionUrl.absoluteString)
json["isCancel"] = false
Expand All @@ -245,8 +236,8 @@ public class SwiftVideoCompressPlugin: NSObject, FlutterPlugin {
}

private func cancelCompression(_ result: FlutterResult) {
exporter?.cancelExport()
stopCommand = true
exporter?.cancelExport()
result("")
}

Expand Down
8 changes: 4 additions & 4 deletions lib/src/video_compress/video_compressor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ extension Compress on IVideoCompress {
Future<Uint8List> getByteThumbnail(
String path, {
int quality = 100,
int position = -1,
num position = 0,
}) async {
assert(path != null);
assert(quality > 1 || quality < 100);
Expand All @@ -71,7 +71,7 @@ extension Compress on IVideoCompress {
Future<File> getFileThumbnail(
String path, {
int quality = 100,
int position = -1,
num position = 0,
}) async {
assert(path != null);
assert(quality > 1 || quality < 100);
Expand Down Expand Up @@ -122,8 +122,8 @@ extension Compress on IVideoCompress {
String path, {
VideoQuality quality = VideoQuality.DefaultQuality,
bool deleteOrigin = false,
int startTime,
int duration,
num startTime,
num duration,
bool includeAudio,
int frameRate = 30,
}) async {
Expand Down