1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- import 'dart:io';
- import 'dart:typed_data';
- import 'package:dio/dio.dart' as dio;
- import 'package:vid/us/vid_us_image.dart';
- import 'package:vid/us/vid_us_image_data.dart';
- class VidFileHelper {
-
-
- static Future<VidUsImage?> getImageFromFile(File file) async {
- final data = await getDataFromFile(file);
- if (data != null) {
- final frame = data.getImage(0);
- return frame;
- }
- return null;
- }
-
-
- static Future<VidUsImageData?> getDataFromFile(File file) async {
- try {
- final fileData = await file.readAsBytes();
- final vidData = VidUsImageData(fileData);
- return vidData;
- } catch (e) {
-
- return null;
- }
- }
-
-
- static Future<VidUsImage?> getImageFromNetwork(String url) async {
- final data = await getDataFromNetwork(url);
- if (data != null) {
- final frame = data.getImage(0);
- return frame;
- }
- return null;
- }
-
-
- static Future<VidUsImageData?> getDataFromNetwork(String url) async {
- try {
- final httpClient = dio.Dio(dio.BaseOptions(
- responseType: dio.ResponseType.bytes,
- sendTimeout: 10 * 1000,
- ));
- final response = await httpClient.get(url);
- httpClient.close();
- final bytes = response.data as Uint8List;
- final vidData = VidUsImageData(bytes);
- return vidData;
- } catch (e) {
-
- return null;
- }
- }
- }
|