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 @@ -258,12 +258,15 @@ public void run() {
map.put("path", path);

String thumbPath;
double duration = 0;
if (media.getMimeType().contains("image")) {
thumbPath = path;
} else {
thumbPath = createVideoThumb(path);
duration = media.getDuration()/1000.0;
}
map.put("thumbPath", thumbPath);
map.put("duration", duration);

int size = getFileSize(path);
map.put("size", size);
Expand Down
14 changes: 12 additions & 2 deletions ios/Classes/SwiftImagesPickerPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,12 @@ public class SwiftImagesPickerPlugin: NSObject, FlutterPlugin {
let videoUrl = avasset as! AVURLAsset;
let url = videoUrl.url;
// TODO: mov to mp4
resArr.append(self.resolveVideo(url: url));
let dir =self.resolveVideo(url: url);
// let audioDuration = videoUrl.duration;
// let audioDurationSeconds = CMTimeGetSeconds(audioDuration);
//dir.updateValue(audioDurationSeconds, forKey: "duration");

resArr.append(dir);
group.leave();
})
} else {
Expand Down Expand Up @@ -298,7 +303,12 @@ public class SwiftImagesPickerPlugin: NSObject, FlutterPlugin {
let urlStr = url.absoluteString;
let path = (urlStr as NSString).substring(from: 7);
dir.updateValue(path, forKey: "path");


let video = AVURLAsset(url:url);
let audioDuration = video.duration;

let audioDurationSeconds = CMTimeGetSeconds(audioDuration);
dir.updateValue(audioDurationSeconds, forKey: "duration");
// 获取视频封面图
if let thumb = self.getVideoThumbPath(url: path) {
let thumbData = thumb.jpegData(compressionQuality: 1); // 转Data
Expand Down
12 changes: 7 additions & 5 deletions lib/images_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class ImagesPicker {
path: image["path"],
size: ((image["size"] ?? 0) / 1024).toDouble(),
thumbPath: image["thumbPath"],
duration: image["duration"] ?? 0,
);
return media;
}).toList();
Expand Down Expand Up @@ -96,6 +97,7 @@ class ImagesPicker {
path: image["path"],
size: ((image["size"] ?? 0) / 1024).toDouble(),
thumbPath: image["thumbPath"],
duration: image["duration"] ?? 0,
);
return media;
}).toList();
Expand Down Expand Up @@ -194,9 +196,9 @@ class Media {
/// 文件大小
double size;

Media({
required this.path,
this.thumbPath,
required this.size,
});
// 时长 仅视频有效
double? duration;

Media(
{required this.path, this.thumbPath, required this.size, this.duration});
}