问题描述
我在加密和解密视频文件以及加密视频文件时遇到问题。没有任何错误。但在加密和解密视频文件时卡住了。我使用异步方法。但它仍然卡住。我的代码如下。
加密:
Future sifrele() async {
try {
crypt.setoverwriteMode(AesCryptOwMode.on);
encFilepath = await crypt.encryptFile(realPath + '/WhatCarCanYouGetForAGrand.mp4',realPath + '/video.mp4.aes');
print('The encryption has been completed successfully.');
} on AesCryptException catch (e) {
if (e.type == AesCryptExceptionType.destFileExists) {
print('The encryption has been completed unsuccessfully.');
}
return;
}
}
解密:
Future decrypting() async {
var videos = File(realPath + "/ElephantsDream.mp4.aes");
try {
realPath = await crypt.decryptFile(realPath + '/video.mp4.aes',realPath + '/cozulen.mp4');
print('The decryption has been completed successfully.');
} on AesCryptException catch (e) {
if (e.type == AesCryptExceptionType.destFileExists) {
print('The decryption has been completed unsuccessfully.');
}
return;
}
}
谢谢。
解决方法
为避免造成麻烦,您需要在后台执行类似这样的昂贵计算。在Android上,这意味着在另一个线程上安排工作。在Flutter中,您可以使用单独的Isolate和Compute。您可能应该需要这样的东西:
void _Startdecrypting(){
compute(decrypting,/** If you need any input for your method put them here **/);
}
decrypting() {
var videos = File(realPath + "/ElephantsDream.mp4.aes");
try {
realPath = crypt.decryptFile(realPath + '/video.mp4.aes',realPath + '/cozulen.mp4');
print('The decryption has been completed successfully.');
} on AesCryptException catch (e) {
if (e.type == AesCryptExceptionType.destFileExists) {
print('The decryption has been completed unsuccessfully.');
}
return;
}
}
,
对于其他用户来这里,关于同一主题的答案在这里Flutter: run multiple methods