【问题标题】:How to save URI to file如何将URI保存到文件
【发布时间】: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)

标签: c# unity3d uwp hololens


【解决方案1】:

在 Unity 中,您无权访问 HttpClient。您可以更改为使用WWW 类。 记得检查Internet Client 功能。

【讨论】:

  • 抱歉,我认为您是在 Unity 中制作的,因为您添加了该标签。
猜你喜欢
  • 2021-07-16
  • 1970-01-01
  • 2020-04-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-27
  • 2011-01-18
相关资源
最近更新 更多