首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将mp3文件从孤立存储复制到windows 8中的媒体库

将mp3文件从孤立存储复制到windows 8中的媒体库
EN

Stack Overflow用户
提问于 2015-08-06 15:47:56
回答 1查看 324关注 0票数 1

我能够将媒体文件存储到隔离存储中,并能够检索这些文件。现在我想要的是在电话中播放音乐播放器中的文件,但是音乐播放器说“找不到音乐”。如何将在隔离存储中下载的mp3文件显示给媒体库?我使用这段代码下载mp3文件。有没有办法将文件下载到可读的存储器(电话内存/内部存储/存储卡)?

代码语言:javascript
复制
  void imgDown_Tap(object sender, System.Windows.Input.GestureEventArgs e)
    {
        ToastPrompt toast = new ToastPrompt();
        toast.Foreground = new SolidColorBrush(Colors.Black);
        toast.FontSize = 20;
        toast.Background = new SolidColorBrush(Colors.Yellow);
        toast.Message = "Please wait";
        toast.Show();
try
        {
            //Create a webclient that'll handle your download
            WebClient client = new WebClient();
            //Run function when resource-read (OpenRead) operation is completed
            client.OpenReadCompleted += client_OpenReadCompleted;
            //Start download / open stream
            client.OpenReadAsync(new Uri(streamUrl));
}
        catch (Exception ex)
        {
            toast.Message = "Downloading error";
            toast.Show();
        }
    }
    async void client_OpenReadCompleted(object sender, 
OpenReadCompletedEventArgs e)
    {
        ToastPrompt toast = new ToastPrompt();
        toast.Foreground = new SolidColorBrush(Colors.Black);
        toast.FontSize = 20;
        toast.Background = new SolidColorBrush(Colors.Yellow);
        toast.Message = "Downloading starts";
        toast.Show();
        try
        {

            byte[] buffer = new byte[e.Result.Length];
            //Store bytes in buffer, so it can be saved later on
            await e.Result.ReadAsync(buffer, 0, buffer.Length);


            using (IsolatedStorageFile file 
            IsolatedStorageFile.GetUserStoreForApplication())
            {

                //Create file
                using (IsolatedStorageFileStream stream =
file.OpenFile(titleUrl+".mp3", FileMode.Create))
                {
                    //Write content stream to file
                    await stream.WriteAsync(buffer, 0, buffer.Length);
                }
               // StorageFolder local = 
Windows.Storage.ApplicationData.Current.LocalFolder;
                //StorageFile storedFile = await local.GetFileAsync(titleUrl + 
".mp3");

                toast.Message = "Downloading complete";
                toast.Show();
        }
        catch (Exception ex)
        {

            toast.Message = "We could not finish your download. Error ";
            toast.Show();
        }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-08-06 16:00:23

看起来您需要使用MediaLibraryExtensions.SaveSong方法(参见https://msdn.microsoft.com/library/microsoft.xna.framework.media.PhoneExtensions.medialibraryextensions.savesong(v=xnagamestudio.42).aspx )

您需要将ID_CAP_MEDIALIB_AUDIO功能添加到应用程序中,并为隔离存储上的文件获取一个URI以传递给该方法。

在MSDN上有一些关于Windows数据的更多信息。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31860250

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档