feat: add video batch upload queue
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:wechat_assets_picker/wechat_assets_picker.dart';
|
||||
|
||||
import 'video_batch_upload_config.dart';
|
||||
import 'video_batch_upload_task.dart';
|
||||
|
||||
class VideoBatchUploadPicker {
|
||||
const VideoBatchUploadPicker._();
|
||||
|
||||
static Future<List<VideoBatchUploadTask>> pickVideos(
|
||||
BuildContext context, {
|
||||
int maxAssets = VideoBatchUploadConfig.maxAssets,
|
||||
}) async {
|
||||
final List<AssetEntity>? assets = await AssetPicker.pickAssets(
|
||||
context,
|
||||
pickerConfig: AssetPickerConfig(
|
||||
maxAssets: maxAssets,
|
||||
requestType: RequestType.video,
|
||||
),
|
||||
);
|
||||
if (assets == null || assets.isEmpty) {
|
||||
return <VideoBatchUploadTask>[];
|
||||
}
|
||||
|
||||
final List<VideoBatchUploadTask> tasks = <VideoBatchUploadTask>[];
|
||||
for (final AssetEntity asset in assets) {
|
||||
final File? file = await asset.file;
|
||||
if (file == null) {
|
||||
continue;
|
||||
}
|
||||
final Uint8List? thumbnail = await asset.thumbnailDataWithSize(
|
||||
const ThumbnailSize.square(220),
|
||||
quality: 72,
|
||||
);
|
||||
final int fileSize = await file.length();
|
||||
tasks.add(
|
||||
VideoBatchUploadTask(
|
||||
id: '${asset.id}_${DateTime.now().microsecondsSinceEpoch}',
|
||||
file: file,
|
||||
fileName: _normalizeFileName(asset.title, file.path),
|
||||
fileSize: fileSize,
|
||||
duration: asset.duration,
|
||||
thumbnail: thumbnail,
|
||||
),
|
||||
);
|
||||
}
|
||||
return tasks;
|
||||
}
|
||||
|
||||
static String _normalizeFileName(String? assetTitle, String path) {
|
||||
final String title = (assetTitle ?? '').trim();
|
||||
if (title.isNotEmpty) {
|
||||
return title;
|
||||
}
|
||||
final List<String> segments = path.split(Platform.pathSeparator);
|
||||
final String fileName = segments.isEmpty ? '' : segments.last.trim();
|
||||
return fileName.isEmpty ? 'video.mp4' : fileName;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user