generateImages method
- {required AppModel appModel,
- required MediaItem item,
- List<
Subtitle> ? subtitles, - SubtitleOptions? options,
- String? data}
override
If this source is non-null, this will be used as the initial function for the image field over the auto enhancement. Extra durations can be invoked and defined when initially opening the creator, to call attention to multiple durations to be used for image generation.
Implementation
@override
Future<List<NetworkToFileImage>> generateImages({
required AppModel appModel,
required MediaItem item,
List<Subtitle>? subtitles,
SubtitleOptions? options,
String? data,
}) async {
List<NetworkToFileImage> imageFiles = [];
Directory appDirDoc = await getApplicationSupportDirectory();
String mokuroPreviewPath = '${appDirDoc.path}/mokuroImagePreview';
Directory mokuroPreviewDir = Directory(mokuroPreviewPath);
if (mokuroPreviewDir.existsSync()) {
mokuroPreviewDir.deleteSync(recursive: true);
}
mokuroPreviewDir.createSync();
String timestamp = DateFormat('yyyyMMddTkkmmss').format(DateTime.now());
Directory imageDir = Directory('$mokuroPreviewPath/$timestamp');
imageDir.createSync();
File file = appModel.getPreviewImageFile(imageDir, 0);
if (data != null) {
if (item.mediaIdentifier.startsWith('file://')) {
String absolutePath = Uri.decodeFull(
Uri.parse(item.mediaIdentifier.replaceFirst('file://', ''))
.resolve(data)
.toString());
File originalFile = File(absolutePath);
originalFile.copySync(file.path);
imageFiles.add(NetworkToFileImage(file: file));
} else {
String absolutePath = Uri.decodeFull(
Uri.parse(item.mediaIdentifier).resolve(data).toString());
File networkFile =
await DefaultCacheManager().getSingleFile(absolutePath);
networkFile.copySync(file.path);
imageFiles.add(
NetworkToFileImage(
url: data,
file: file,
),
);
}
}
return imageFiles;
}