feat(android,interface): Implement video thumbnail generation

This commit is contained in:
2023-08-24 20:06:31 +02:00
parent fb71ac330a
commit fe6d0a60c1
12 changed files with 183 additions and 2 deletions

View File

@@ -4,6 +4,7 @@ import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:file_picker/file_picker.dart';
import 'package:moxplatform/moxplatform.dart';
import 'package:path/path.dart';
import 'package:permission_handler/permission_handler.dart';
/// The id of the notification channel.
@@ -286,6 +287,43 @@ class MyHomePageState extends State<MyHomePage> {
},
child: const Text('Open battery optimisation page'),
),
ElevatedButton(
onPressed: () async {
final result = await FilePicker.platform.pickFiles(
type: FileType.video,
);
if (result == null) return;
final path = result.files.single.path!;
final storagePath =
await MoxplatformPlugin.platform.getPersistentDataPath();
final mediaPath = join(storagePath, 'media');
if (!Directory(mediaPath).existsSync()) {
await Directory(mediaPath).create(recursive: true);
}
final internalPath = join(mediaPath, basename(path));
print('Copying file');
await File(path).copy(internalPath);
print('Generating thumbnail');
final thumbResult =
await MoxplatformPlugin.platform.generateVideoThumbnail(
internalPath,
'$internalPath.thumbnail.jpg',
720,
);
print('Success: $thumbResult');
await showDialog<void>(
context: context,
builder: (context) => Image.file(
File('$internalPath.thumbnail.jpg'),
),
);
},
child: const Text('Thumbnail'),
)
],
),
),

View File

@@ -39,6 +39,8 @@ dependencies:
file_picker: 5.2.0+1
path: 1.8.3
permission_handler: 10.4.3
# The following adds the Cupertino Icons font to your application.