I am developing an app in flutter which has requirements to load some videos in cache and then play it respectively.
below is my code what actually i am doing,
<code>void downloadFile() async {
var cacheFile = DefaultCacheManager();
// get file path from server
var list = await giftOperations.getGiftName("1");
// check if file is already cached or not
for (var element in list) {
var url = AppUrl.newBaseUrl + (element.animationFilePath ?? "");
// if file is not cached then get the file from server and cache it
var fileCachedAlready = await cacheFile.getFileFromCache(url);
// if file is already cached then add it to the list
if (fileCachedAlready != null && fileCachedAlready.file.existsSync()) {
// do some code here
} else {
// download file from server through url and cache it
await cacheFile.downloadFile(url);
// add the file to the list
}
}
</code>
<code>void downloadFile() async {
var cacheFile = DefaultCacheManager();
// get file path from server
var list = await giftOperations.getGiftName("1");
// check if file is already cached or not
for (var element in list) {
var url = AppUrl.newBaseUrl + (element.animationFilePath ?? "");
// if file is not cached then get the file from server and cache it
var fileCachedAlready = await cacheFile.getFileFromCache(url);
// if file is already cached then add it to the list
if (fileCachedAlready != null && fileCachedAlready.file.existsSync()) {
// do some code here
} else {
// download file from server through url and cache it
await cacheFile.downloadFile(url);
// add the file to the list
}
}
</code>
void downloadFile() async {
var cacheFile = DefaultCacheManager();
// get file path from server
var list = await giftOperations.getGiftName("1");
// check if file is already cached or not
for (var element in list) {
var url = AppUrl.newBaseUrl + (element.animationFilePath ?? "");
// if file is not cached then get the file from server and cache it
var fileCachedAlready = await cacheFile.getFileFromCache(url);
// if file is already cached then add it to the list
if (fileCachedAlready != null && fileCachedAlready.file.existsSync()) {
// do some code here
} else {
// download file from server through url and cache it
await cacheFile.downloadFile(url);
// add the file to the list
}
}
then i get the file through the following code.
<code> var cachedFile = await DefaultCacheManager().getFileFromCache(giftName.animationFilePath);
ByteData data = await rootBundle.load(cachedFile!.file.path);
List<int> bytes = data.buffer.asUint8List();
var memory = Uint8List.fromList(bytes);
</code>
<code> var cachedFile = await DefaultCacheManager().getFileFromCache(giftName.animationFilePath);
ByteData data = await rootBundle.load(cachedFile!.file.path);
List<int> bytes = data.buffer.asUint8List();
var memory = Uint8List.fromList(bytes);
</code>
var cachedFile = await DefaultCacheManager().getFileFromCache(giftName.animationFilePath);
ByteData data = await rootBundle.load(cachedFile!.file.path);
List<int> bytes = data.buffer.asUint8List();
var memory = Uint8List.fromList(bytes);
But here it throws the following error
<code>FlutterError (Unable to load asset: "/data/user/0/com.example.mvvm/cache/libCachedImageData/3169cb20-5a38-11ef-b7b9-23c107b39441.mp4".
The asset does not exist or has empty data.)
</code>
<code>FlutterError (Unable to load asset: "/data/user/0/com.example.mvvm/cache/libCachedImageData/3169cb20-5a38-11ef-b7b9-23c107b39441.mp4".
The asset does not exist or has empty data.)
</code>
FlutterError (Unable to load asset: "/data/user/0/com.example.mvvm/cache/libCachedImageData/3169cb20-5a38-11ef-b7b9-23c107b39441.mp4".
The asset does not exist or has empty data.)
What i am missing. Any help will be really appreciated.
And downloading data from server is very time consuming. Is there any way to run this parallel, fast and optimized.