下载文件后如何将音乐从隔离存储复制到Music Hub?

时间:2014-07-11 11:43:27

标签: c# windows-phone-8 windows-phone

我使用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);
    }

预期是: enter image description here

0 个答案:

没有答案