0
string url = "http://any_urls";
MediaPlayer player = new MediaPlayer();
public MainPage()
{
InitializeComponent();
Debug.WriteLine("Download started");
var file = Download().Result; // <-- Here's where it stucks
Debug.WriteLine("Download finished");
player.Source = MediaSource.CreateFromStorageFile(file);
player.Play();
}
private async Task<StorageFile> Download()
{
StorageFile destinationFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(
"data.mp3", CreationCollisionOption.GenerateUniqueName);
BackgroundDownloader downloader = new BackgroundDownloader();
DownloadOperation download = downloader.CreateDownload(new Uri(url), destinationFile);
await download.StartAsync();
return destinationFile;
}
我已經在個人電腦和手機上測試過,它們都凍結了整個過程。任何人都可以解決這個問題,或者任何其他的替代方案?即使在PC上,UWP BackgroundDownloader仍然凍結