【问题标题】:c# Stream.ReadAsync reads zero bytes, although the end of the stream was not reachedc# Stream.ReadAsync 读取零字节,虽然没有到达流的末尾
【发布时间】:2015-04-03 22:01:16
【问题描述】:

我正在尝试使用 http 发送 mp4 流,但每次我的循环在第一次迭代期间中断,因为 ReadAsync 返回 0。我不明白为什么,因为我检查流是否为空,当然不是.

这是我目前得到的:

while (camera.VideoStream.AsStream().Length == 0);

byte[] buffer = new byte[1024];
while (true)
{
    int bytesRead = await camera.VideoStream.AsStream().ReadAsync(buffer,0,buffer.Length);
    if (bytesRead == 0)
    {
        Debug.WriteLine("End of Stream");
        break;
    }
    await output.WriteAsync(buffer, 0, bytesRead);
    await output.FlushAsync();
}

camera.VideoStream 是一个 IRandomAccessStream。

感谢您的帮助。

【问题讨论】:

    标签: c# http windows-phone-8.1 streaming mp4


    【解决方案1】:

    当您尝试读取流时,流的位置是什么?

    您可能需要 .Seek(0, SeekOrigin.Begin)。

    【讨论】:

      猜你喜欢
      • 2021-07-30
      • 2020-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-05
      • 1970-01-01
      • 1970-01-01
      • 2014-09-17
      相关资源
      最近更新 更多