You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to convert mp4 video to LivePhoto from url
Error: PlatformException(PHPhotosErrorDomain (-1), The operation couldn’t be completed. (PHPhotosErrorDomain error -1.), No failure reason provided, null)
My code
import 'dart:io';
import 'package:flutter/services.dart';
import 'package:http/http.dart' as http;
import 'package:material_wallpapers_ios/sources.dart';
import 'package:path_provider/path_provider.dart';
import 'package:photo_manager/photo_manager.dart';
import 'package:video_thumbnail/video_thumbnail.dart';
mixin LivePhotoManager {
// Downloads a file from a URL and returns the file.
static Future<File> downloadFile(String url, String fileName) async {
try {
final response = await http.get(Uri.parse(url));
if (response.statusCode != 200) {
throw Exception('Failed to download file: ${response.statusCode}');
}
final bytes = response.bodyBytes;
final dir = await getTemporaryDirectory();
final file = File('${dir.path}/$fileName');
await file.writeAsBytes(bytes);
return file;
} catch (e) {
FlutterLogger.error('Failed to download file: $e');
rethrow;
}
}
// Main function to create a live photo from an image and video URL.
static Future<bool> createLivePhoto(String imageUrl, String videoUrl) async {
try {
// Step 1: Download image and video
final imageFile = await downloadFile(imageUrl, 'live_photo.heic');
final videoFile = await downloadFile(videoUrl, 'live_video.mp4');
// Step 2: Validate the files exist and are of the correct types
if (!(await imageFile.exists()) || !(await videoFile.exists())) {
throw Exception('One or both files do not exist or are invalid.');
}
// Step 3: Check that the image is in HEIC format
if (!imageFile.path.endsWith('.heic')) {
throw Exception('The image file must be in HEIC format.');
}
// Step 4: Check that the video is in MP4 format
if (!videoFile.path.endsWith('.mp4')) {
throw Exception('The video file must be in MP4 format.');
}
FlutterLogger.info(imageFile.path);
FlutterLogger.info(videoFile.path);
// Step 5: Save the live photo
final AssetEntity entity = await PhotoManager.editor.darwin.saveLivePhoto(
imageFile: imageFile,
videoFile: videoFile,
title: 'LivePhoto_Example.heic',
);
FlutterLogger.success('Live photo saved successfully: ${entity.id}');
return true;
} catch (e) {
// Handle the error and provide better logs.
FlutterLogger.error('Error creating live photo: $e');
if (e is PlatformException) {
// Handle platform-specific errors (e.g., permission issues, file access issues)
FlutterLogger.error('Platform-specific error: ${e.message}');
FlutterLogger.error('Error code: ${e.code}');
}
return false;
}
}
}
Try do it
No response
The text was updated successfully, but these errors were encountered:
AI Summary: The user is encountering a PHPhotosErrorDomain error -1 when trying to create a Live Photo from an MP4 video on iOS. The code downloads an image and video, then attempts to save them as a Live Photo.
Platforms
iOS
Description
I am trying to convert mp4 video to LivePhoto from url
Error: PlatformException(PHPhotosErrorDomain (-1), The operation couldn’t be completed. (PHPhotosErrorDomain error -1.), No failure reason provided, null)
My code
Try do it
No response
The text was updated successfully, but these errors were encountered: