我使用Background Transfer Service
通过以下代码从服务器下载文件:
private void ProcessTransfer(BackgroundTransferRequest transfer)
{
switch (transfer.TransferStatus)
{
case TransferStatus.Completed:
if (transfer.StatusCode == 200 || transfer.StatusCode == 206)
{
using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
{
filename = transfer.Tag;
if (isoStore.FileExists(filename)) isoStore.DeleteFile(filename);
if (isoStore.FileExists(transfer.DownloadLocation.OriginalString)) isoStore.MoveFile(transfer.DownloadLocation.OriginalString, filename);
MoveMp3ToMusicHub();
}
}
break;
}
}
我正在尝试使用以下代码将下载的mp3文件移动到Music Hub,但是出现意外异常。
private void MoveMp3ToMusicHub()
{
MediaLibrary lib = new MediaLibrary();
Uri location = new Uri("isostore:/" + filename, UriKind.Absolute);
SongMetadata metadata = new SongMetadata
{
GenreName = "Super Hit Songs",
Name = "Song 1",
AlbumName = "My Collections",
AlbumArtUri = new Uri("/Assets/ApplicationIcon.png", UriKind.RelativeOrAbsolute)
};
MediaLibraryExtensions.SaveSong(lib, location, metadata, SaveSongOperation.CopyToLibrary);
}
预期是: