0

我想从中运行Background file transferBackground audio agent但在前台应用程序中运行正确的示例代码出现错误。

这是示例:

string transferFileName = @"http://www.reggaeavenue.com/MP3/leave%20short.mp3";
Uri transferUri = new Uri(Uri.EscapeUriString(transferFileName), UriKind.RelativeOrAbsolute);

BackgroundTransferRequest transferRequest = new BackgroundTransferRequest(transferUri);

transferRequest.Method = "GET";

string downloadFile = "result.mp3";
Uri downloadUri = new Uri("shared/transfers/" + downloadFile, UriKind.RelativeOrAbsolute);
transferRequest.DownloadLocation = downloadUri;

transferRequest.Tag = downloadFile;

transferRequest.TransferPreferences = TransferPreferences.AllowCellularAndBattery;

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.");
}

在将 transferRequest 添加到 BackgroundTransferService 的行中,我收到错误:

System.InvalidOperationException: Operation is not valid due to the current state of the object.
   at Microsoft.Phone.BackgroundTransfer.BackgroundTransferRequest.SubmitHelper()
   at Microsoft.Phone.BackgroundTransfer.BackgroundTransferRequest.Submit()
   at Microsoft.Phone.BackgroundTransfer.BackgroundTransferService.Add(BackgroundTransferRequest request)
   at Project.AudioPlaybackAgent.AudioPlayer.CreateBackgroundTransfer()

那么可以从后台代理运行 transferm 吗?我怎样才能解决这个问题?谢谢

4

1 回答 1

2

根据MSDN,后台代理不支持某些 API(包括后台传输)。即使您设法做一些事情,您的应用程序也可能无法通过认证测试。

为什么不在主 UI 中下载文件或直接从网络源播放?

于 2013-12-22T11:05:13.203 回答