0

Background file transferから実行したいのですがBackground 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 でファイルをダウンロードしたり、Web ソースから直接再生したりしないのはなぜですか?

于 2013-12-22T11:05:13.203 に答える