我是Xamarin iOS的新用户,我需要同时下载多个视频。我该怎么做到这一点?是否有任何类可以帮助我下载类似于Android中的DownloadManager。
答案 0 :(得分:0)
您可以尝试这种方法
public void getData(List<String> urls) {
// define the HttpClient
var handler = new HttpClientHandler { AllowAutoRedirect=false };
var client = new HttpClient(handler);
// define file path
var path=Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
// start download
System.Threading.Tasks.Parallel.ForEach(urls, async (url) => {
var uri = new Uri(url);
var fileName = System.IO.Path.GetFileName(uri.LocalPath);
// download the file
var data = await client.GetByteArrayAsync(uri);
// save file on disk
System.IO.File.WriteAllBytes(System.IO.Path.Combine(path, fileName), data);
});
}