download method

  1. @override
Future<Uint8List?> download(
  1. DownloadTask task
)
override

Downloads data from the network for the given task.

Returns a Uint8List containing the downloaded data, or null if the download fails.

Implementation

@override
Future<Uint8List?> download(DownloadTask task) async {
  logD('From network: ${task.url}');
  Uint8List? dataNetwork;
  String cachePath = await FileExt.createCachePath(task.uri.generateMd5);
  task.cacheDir = cachePath;
  await VideoProxy.downloadManager.executeTask(task);
  await for (DownloadTask taskStream in VideoProxy.downloadManager.stream) {
    if (taskStream.status == DownloadStatus.COMPLETED &&
        taskStream.matchUrl == task.matchUrl) {
      dataNetwork = Uint8List.fromList(taskStream.data);
      break;
    }
  }
  return dataNetwork;
}