gpt4 book ai didi

c# - wp8-如何将下载的文件访问到隔离存储中

转载 作者:太空宇宙 更新时间:2023-11-03 15:55:12 27 4
gpt4 key购买 nike

你好,在我的应用程序中,我将“.mp3”文件下载到隔离存储中,用户应该能够收听这个“.mp3”文件,但似乎我无法在播放点击事件中访问“.mp3”文件

这是我的代码

 private IsolatedStorageFile isoStore;
public mp3kuran()
{
InitializeComponent();
using ( isoStore= IsolatedStorageFile.GetUserStoreForApplication())
{
if (!isoStore.DirectoryExists("/shared/transfers"))
{
isoStore.CreateDirectory("/shared/transfers");
}
}
}

string link= "https://dl.dropboxusercontent.com/u/75638865/001.mp3";

private BackgroundTransferRequest transferRequest;

这是我下载 mp3 文件的下载按钮操作

        private void download_Click(object sender, RoutedEventArgs e)
{

Uri transferuri = new Uri(Uri.EscapeUriString(link), UriKind.RelativeOrAbsolute);
// Create the new transfer request, passing in the URI of the file to
// be transferred.
transferRequest = new BackgroundTransferRequest(transferuri);
// Set the transfer method. GET and POST are supported.
transferRequest.Method = "GET";
string downloadFile = link.Substring(link.LastIndexOf("/") + 1);
Uri downloadUri = new Uri("shared/transfers/" + downloadFile, UriKind.RelativeOrAbsolute);
transferRequest.DownloadLocation = downloadUri;
transferRequest.Tag = downloadFile;
// Add the transfer request using the BackgroundTransferService. Do this in
// a try block in case an exception is thrown.
try
{
BackgroundTransferService.Add(transferRequest);
}
catch (InvalidOperationException ex)
{
MessageBox.Show("Unable to add background transfer request. " + ex.Message);
}
catch (Exception)
{
MessageBox.Show("Unable to add background transfer request.");
}

}

这里播放按钮点击事件

        private void play_Click(object sender, RoutedEventArgs e)
{
string fileName = transferRequest.Tag;
MessageBox.Show(fileName);

using (var isoStore = IsolatedStorageFile.GetUserStoreForApplication())
{
if (isoStore.FileExists(fileName))
{MessageBox.Show("here");
using (var isoStream = isoStore.OpenFile(fileName, FileMode.Open, FileAccess.Read))
{
mediaSound.Stop();
mediaSound.SetSource(isoStream);

mediaSound.Position = System.TimeSpan.FromSeconds(0);
mediaSound.Volume = 20;
mediaSound.Play();
}
}

}
}

在 play_clic 事件中,我尝试从隔离存储中访问 mp3,但我无法解决问题,因为当我单击按钮时,它什么都不做

最佳答案

一些想法...

您是否在允许单击播放按钮之前检查 BackgroundTransferRequest 是否已完成?

通过检查是否存在与原始文件大小相同的物理文件,您确定已成功下载完整文件吗?您可以使用类似 Windows Phone Toolkit 的工具检查这个。

在下载完成后,您的 BackgroundTransferRequest 上的 Tag 属性是否保持正确的值?

通常您会检查 BackgroundTransferRequest 的状态并将文件从“/shared/transfers”复制到您自己的位置。然后您将从该位置播放该文件。

关于c# - wp8-如何将下载的文件访问到隔离存储中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23973114/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com