0

大家好,我有一个小的 winrt 应用程序,可以从互联网下载视频,我试图一起实现 backgrounddownloader 和 filesavepicker,但是我在搜索谷歌的每种类型的实现中运行错误,我搜索了微软文档但没有。我通过 HttpClient 类实现了下载但我想要的是获得下载进度并且 HttpClient 不提供它。提前谢谢

4

1 回答 1

0

这是一个快速示例,如何做到这一点:

// set download URI
var uri = new Uri("http://s3.amazonaws.com/thetabletshow/thetabletshow_0072_lhotka.mp3");
// get destination file
var picker = new FileSavePicker();
// set allowed extensions
picker.FileTypeChoices.Add("MP3", new List<string> { ".mp3" });
var file = await picker.PickSaveFileAsync();

// create a background download
var downloader = new BackgroundDownloader();
var download = downloader.CreateDownload(uri, file);

// create progress object
var progress = new Progress<DownloadOperation>();
// attach an event handler to get notified on progress
progress.ProgressChanged += (o, operation) => 
    { 
        // use the progress info in Progress.BytesReceived and Progress.TotalBytesToReceive
        ProgressText.Text = operation.Progress.BytesReceived.ToString(); 
    };
// start the actual download
await download.StartAsync().AsTask(progress);

从这里开始,您应该能够根据您的需要对其进行修改。

于 2013-05-24T05:08:16.383 回答