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
When I compress the VideoSize >=10MB
After compression it almost double the initial size ,you can check in given text.
I/hw-BpHwBinder(14438): onLastStrongRef automatically unlinking death recipients
I/flutter (14438): Original File Size in MB: 84.54
I/flutter (14438): Compressed File Size in MB: 112.64
I/flutter (14438): Compressed video path: /data/user/0/football.interkashi.debug/app_flutter/compressed_video.mp4
CODE -
import 'dart:io';
import 'package:get/get.dart';
import 'package:interkashi/modules/components/extension/get_extension.dart';
import 'package:interkashi/modules/feature/academy/model/training_video_upload_model.dart';
import 'package:interkashi/modules/feature/academy/service/upload_video_service.dart';
import 'package:path_provider/path_provider.dart';
import 'package:video_compress/video_compress.dart'; // Assuming this is the same as your custom implementation
// Use the custom video compressor instance
final IVideoCompress videoCompressor = VideoCompress;
class UploadVideoController extends GetxController {
final UploadVideoService _uploadVideoService;
UploadVideoController(this._uploadVideoService);
Rxn selectedVideoPath = Rxn();
RxBool isUploading = RxBool(false);
RxDouble uploadProgress = RxDouble(0.0);
Rx<bool?> uploadSuccess = Rx<bool?>(null);
final double maxSizeMB = 100;
RxBool flag = true.obs;
late String lessonId;
late String courseId;
// Subscribe to the compression progress stream
videoCompressor.compressProgress$.subscribe((progress) {
uploadProgress.value = progress / 100;
});
}
Future compressVideo(String path) async {
// Compress the video using the custom IVideoCompress implementation
final info = await videoCompressor.compressVideo(
path,
quality: VideoQuality.Res640x480Quality,
deleteOrigin: false,
includeAudio: false,
frameRate: 24,
);
if (info != null && info.path != null) {
// Save the compressed video
Directory svdir = await getApplicationDocumentsDirectory();
var svPath = '${svdir.path}/compressed_video.mp4';
File compressedFile = File(info.path!);
File savedFile = await compressedFile.copy(svPath);
selectedVideoPath.value = savedFile.path;
// Calculate and print the file size
int originalSize = File(path).lengthSync();
int compressedSize = savedFile.lengthSync();
double originalSizeMB = originalSize / (1024 * 1024);
double compressedSizeMB = compressedSize / (1024 * 1024);
print("Original File Size in MB: ${originalSizeMB.toStringAsFixed(2)}");
print("Compressed File Size in MB: ${compressedSizeMB.toStringAsFixed(2)}");
// Check if the compressed file size is under the max size
if (compressedSizeMB > maxSizeMB) {
flag.value = false;
GetExt.snackBar("Compressed file size is still larger than 100MB");
} else {
flag.value = true;
}
} else {
GetExt.snackBar("Video compression failed or file path not found.");
}
}
Future checkFileSize(String? video) async {
if (video == null) return;
When I compress the VideoSize >=10MB
After compression it almost double the initial size ,you can check in given text.
I/hw-BpHwBinder(14438): onLastStrongRef automatically unlinking death recipients
I/flutter (14438): Original File Size in MB: 84.54
I/flutter (14438): Compressed File Size in MB: 112.64
I/flutter (14438): Compressed video path: /data/user/0/football.interkashi.debug/app_flutter/compressed_video.mp4
CODE -
import 'dart:io';
import 'package:get/get.dart';
import 'package:interkashi/modules/components/extension/get_extension.dart';
import 'package:interkashi/modules/feature/academy/model/training_video_upload_model.dart';
import 'package:interkashi/modules/feature/academy/service/upload_video_service.dart';
import 'package:path_provider/path_provider.dart';
import 'package:video_compress/video_compress.dart'; // Assuming this is the same as your custom implementation
// Use the custom video compressor instance
final IVideoCompress videoCompressor = VideoCompress;
class UploadVideoController extends GetxController {
final UploadVideoService _uploadVideoService;
UploadVideoController(this._uploadVideoService);
Rxn selectedVideoPath = Rxn();
RxBool isUploading = RxBool(false);
RxDouble uploadProgress = RxDouble(0.0);
Rx<bool?> uploadSuccess = Rx<bool?>(null);
final double maxSizeMB = 100;
RxBool flag = true.obs;
late String lessonId;
late String courseId;
@OverRide
void onInit() {
super.onInit();
final arguments = Get.arguments;
lessonId = arguments['lessonId'];
courseId = arguments['courseId'];
}
Future compressVideo(String path) async {
// Compress the video using the custom IVideoCompress implementation
final info = await videoCompressor.compressVideo(
path,
quality: VideoQuality.Res640x480Quality,
deleteOrigin: false,
includeAudio: false,
frameRate: 24,
);
}
Future checkFileSize(String? video) async {
if (video == null) return;
}
Future uploadVideo() async {
if (selectedVideoPath.value == null || !flag.value) {
return;
}
}
@OverRide
void onClose() {
if (videoCompressor.isCompressing) {
videoCompressor.cancelCompression();
}
videoCompressor.dispose();
super.onClose();
}
Future deleteAllCache() async {
await videoCompressor.deleteAllCache();
}
}
The text was updated successfully, but these errors were encountered: