Flutter 颤振:将缓存的(.file)文件转换为mp4文件

Flutter 颤振:将缓存的(.file)文件转换为mp4文件,flutter,Flutter,我有一个视频文件。我保存以缓存此视频文件。我想在另一页播放这个视频。但当我将此视频保存到缓存时,我不会播放视频。此视频会像这样出现在缓存中 /data/user/0/com.example.flutter_cache_manager/cache/libCachedImageData/fc65e4a0-0fb7-11eb-a1ed-53020f3249ad.file 我需要将此视频转换为.mp4文件 Future addCacheFiles() async { try {

我有一个视频文件。我保存以缓存此视频文件。我想在另一页播放这个视频。但当我将此视频保存到缓存时,我不会播放视频。此视频会像这样出现在缓存中

/data/user/0/com.example.flutter_cache_manager/cache/libCachedImageData/fc65e4a0-0fb7-11eb-a1ed-53020f3249ad.file
我需要将此视频转换为.mp4文件

Future addCacheFiles() async {
        try {
          Uint8List bytes;
          String myPath = realPath + '/WhatCarCanYouGetForAGrand.mp4';
          _readFileByte(myPath).then((bytesData) async {
            bytes = bytesData;
            var file = await DefaultCacheManager().putFile(realPath + "/WhatCarCanYouGetForAGrand.mp4", bytes);
            print(file.path.toString() + " " + "kayıt etti");
          });
        } catch (e) {
          print("hata");
          print(e);
        }
      }

Future<Uint8List> _readFileByte(String filePath) async {
    Uri myUri = Uri.parse(filePath);
    File audioFile = new File.fromUri(myUri);
    Uint8List bytes;
    await audioFile.readAsBytes().then((value) {
      bytes = Uint8List.fromList(value);
      print('reading of bytes is completed');
    }).catchError((onError) {
      print('Exception Error while reading audio from path:' +
          onError.toString());
    });
    return bytes;
  }
Future addCacheFiles()异步{
试一试{
Uint8List字节;
字符串myPath=realPath+'/WhatCarCanYouGetForAGrand.mp4';
_readFileByte(myPath).then((bytesData)异步{
字节=字节数据;
var file=await DefaultCacheManager().putFile(realPath+“/WhatCarCanYouGetForAGrand.mp4”,字节);
打印(file.path.toString()+“”+“kayıt etti”);
});
}捕获(e){
印刷品(“hata”);
印刷品(e);
}
}
Future\u readFileByte(字符串文件路径)异步{
Uri myUri=Uri.parse(filePath);
File audioFile=new File.fromUri(myUri);
Uint8List字节;
等待audioFile.readAsBytes()。然后((值){
字节=Uint8List.fromList(值);
打印(“字节读取完成”);
}).catchError((onError){
打印('从路径读取音频时出现异常错误:'+
onError.toString());
});
返回字节;
}

谢谢。顺便说一下,这段代码正在运行。我只需要转换为mp4文件。

您确定要转换缓存的文件吗

相反,您可以在调用
.putFile
时包含
fileExtension
参数:

var file = await DefaultCacheManager().putFile(realPath + "/WhatCarCanYouGetForAGrand.mp4", bytes, fileExtension: 'mp4');
这样,缓存一开始就不会将其更改为
.file