在 windows phone 8.1 C# 中下载歌曲文件

Downloading song files in windows phone 8.1 C#

I am building an app, that needs to download mp3 files and storage in app folder. My download button is running the structions below.

Uri source = new Uri(url);
string destination = "\mp3";

StorageFile destinationFile = await KnownFolders.PicturesLibrary.CreateFileAsync(
destination, CreationCollisionOption.GenerateUniqueName);

BackgroundDownloader downloader = new BackgroundDownloader();
DownloadOperation download = downloader.CreateDownload(source, destinationFile);

Now i am stopped here, how can i continue with the download file, what method or class i need to continue. I searched about "MediaLibraryExtensions.SaveSong Method" but is this for windows phone 8 and 7.1.

首先,您需要在"destination" 变量中定义正确的文件名。接下来,您将文件保存在错误的音乐文件夹中,歌曲应该在 "KnownFolders.MusicLibrary" 中。如果要下载到应用程序本地文件夹,请使用 ApplicantionData.Current.LocalFolder()。然后,使用下面的代码开始下载(这里没有写progressChanged方法,它是用来跟踪下载过程的,但是你可以很容易地自己定义它):

Progress<DownloadOperation> progress = new Progress<DownloadOperation>(progressChanged);
cancellationToken = new CancellationTokenSource();
await download.StartAsync().AsTask(cancellationToken.Token, progress);