将mp3文件从隔离存储复制到windows phone 8的媒体库

本文关键字:phone windows 媒体库 复制 文件 mp3 隔离 存储 | 更新日期: 2023-09-27 18:06:38

我能够将媒体文件存储到隔离存储中并能够检索相同的文件。现在我想在手机的音乐播放器中播放那个文件,但音乐播放器显示"找不到音乐"我如何在媒体库中显示我下载的独立存储的mp3文件?我正在使用这个代码下载mp3文件。有没有办法下载文件到可读存储(手机内存/内部存储/存储卡)??

  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();
        }

将mp3文件从隔离存储复制到windows phone 8的媒体库

看起来您需要使用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 Phone数据的更多信息