【发布时间】:2018-03-14 23:38:42
【问题描述】:
我正在尝试将 MRC 视频从 Hololens 流式传输到我的 PC;有一个repo that does this,但会将URI 播放到媒体播放器,我正在尝试将其保存到文件中。我怎样才能做到这一点?我已经尝试过使用 HttpClient,但是当我向 URI 发送请求时,应用程序似乎崩溃了。在我附加的链接中,有一个 StartPlayback() 方法将媒体播放器的源属性设置为 URI,它似乎工作正常。我尝试通过以下方式对其进行修改:
private async void StartPlayback()
{
Uri link = new Uri(string.Format("mrvc://{0}:{1}", this.txAddress.Text, this.txPort.Text));
this.videoPlayer.Source = link;
using (var client = new HttpClient())
using (var response = await client.GetAsync(link))
{
// make sure our request was successful
response.EnsureSuccessStatusCode();
// read the filename from the Content-Disposition header
var filename = response.Content.Headers.ContentDisposition.FileName;
// read the downloaded file data
var stream = await response.Content.ReadAsStreamAsync();
// Where you want the file to be saved
var destinationFile = Path.Combine("C:\\Users\\orsteam\\Documents", filename);
// write the steam content into a file
using (var fileStream = File.Create(destinationFile))
{
stream.CopyTo(fileStream);
}
}
this.bnStart.IsEnabled = false;
this.bnStop.IsEnabled = true;
}
谢谢!
【问题讨论】:
-
你的代码有问题吗?
-
我不断收到 'Exception throw: 'System.ArgumentException' in System.Net.Http.dll' - 即使我注释掉响应块它崩溃了,所以似乎问题来了从等待 client.getAsync(link)