mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
mod: save as livephoto for ios
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -6,6 +6,7 @@ import 'package:device_info_plus/device_info_plus.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:live_photo_maker/live_photo_maker.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:saver_gallery/saver_gallery.dart';
|
||||
@@ -86,28 +87,65 @@ class DownloadUtils {
|
||||
return await requestStoragePer(context);
|
||||
}
|
||||
|
||||
static Future downloadVideo(BuildContext context, String url) async {
|
||||
static Future downloadLivePhoto({
|
||||
required BuildContext context,
|
||||
required String url,
|
||||
required String liveUrl,
|
||||
required int width,
|
||||
required int height,
|
||||
}) async {
|
||||
try {
|
||||
if (!await checkPermissionDependOnSdkInt(context)) {
|
||||
return;
|
||||
}
|
||||
SmartDialog.showLoading(msg: '正在下载');
|
||||
|
||||
String tmpPath = (await getTemporaryDirectory()).path;
|
||||
String time = DateTime.now()
|
||||
.toString()
|
||||
.replaceAll(' ', '_')
|
||||
.replaceAll(':', '-')
|
||||
.split('.')
|
||||
.first;
|
||||
late String imageName =
|
||||
"cover_$time.${url.split('.').lastOrNull ?? 'jpg'}";
|
||||
late String imagePath = '$tmpPath/$imageName';
|
||||
String videoName =
|
||||
"video_${DateTime.now().toString().replaceAll(' ', '_').replaceAll(':', '-').split('.').first}.${url.split('.').lastOrNull ?? 'mp4'}";
|
||||
String savePath = '${(await getTemporaryDirectory()).path}/$videoName';
|
||||
await Request.dio.download(url, savePath);
|
||||
SmartDialog.showLoading(msg: '正在保存');
|
||||
final SaveResult result = await SaverGallery.saveFile(
|
||||
filePath: savePath,
|
||||
fileName: videoName,
|
||||
androidRelativePath: "Pictures/PiliPlus",
|
||||
skipIfExists: false,
|
||||
);
|
||||
SmartDialog.dismiss();
|
||||
if (result.isSuccess) {
|
||||
SmartDialog.showToast('「$videoName」已保存 ');
|
||||
"video_$time.${liveUrl.split('.').lastOrNull ?? 'mp4'}";
|
||||
String videoPath = '$tmpPath/$videoName';
|
||||
|
||||
await Request.dio.download(liveUrl, videoPath);
|
||||
|
||||
if (Platform.isIOS) {
|
||||
await Request.dio.download(url, imagePath);
|
||||
SmartDialog.showLoading(msg: '正在保存');
|
||||
bool success = await LivePhotoMaker.create(
|
||||
coverImage: imagePath,
|
||||
imagePath: null,
|
||||
voicePath: videoPath,
|
||||
width: width,
|
||||
height: height,
|
||||
);
|
||||
SmartDialog.dismiss();
|
||||
if (success) {
|
||||
SmartDialog.showToast(' Live Photo 已保存 ');
|
||||
} else {
|
||||
SmartDialog.showToast('保存失败');
|
||||
}
|
||||
} else {
|
||||
SmartDialog.showToast('保存失败,${result.errorMessage}');
|
||||
SmartDialog.showLoading(msg: '正在保存');
|
||||
final SaveResult result = await SaverGallery.saveFile(
|
||||
filePath: videoPath,
|
||||
fileName: videoName,
|
||||
androidRelativePath: "Pictures/PiliPlus",
|
||||
skipIfExists: false,
|
||||
);
|
||||
SmartDialog.dismiss();
|
||||
if (result.isSuccess) {
|
||||
SmartDialog.showToast(' 已保存 ');
|
||||
} else {
|
||||
SmartDialog.showToast('保存失败,${result.errorMessage}');
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user