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?我怎樣才能解決這個問題?謝謝
謝謝,我無法找到它。因爲我想緩存歌曲然後播放它們。我也想從後臺緩存它們。 –
當然,您可以連接背景音頻和您的主UI,主UI下載(在後臺)文件並更新播放列表。在bacgound代理下載可能很困難,請注意,您有限的時間(30秒)結束調用狀態(在發送NotifyComplete()之前) - 如果您的時間用完,您的代理將被終止。 – Romasz
是的,我可以在後臺代理下載它,但是當用戶嘗試使用控件時,什麼都不會發生。必須殺死第一個代理,然後創建處理響應的新代碼,這對我來說是不可接受的。 –