Dear @mc,
After investigating the issue deeper, I found it's UWP app, it shouldn't use ASP.NET Core
Tag.
Since I don't have the environment to test, the sample code should be like below, it can be built successfully, you can try it first.
public class CameraStreamer
{
private BlockingCollection<byte[]> _buffer = new BlockingCollection<byte[]>();
private const int BufferSize = 4096;
public async Task StartRecordToStreamAsync(MediaCapture capture, MediaEncodingProfile profile, Socket socket)
{
var memoryStream = new MemoryStream();
await capture.StartRecordToStreamAsync(profile, memoryStream.AsRandomAccessStream());
Task.Run(() => ReadFromStreamToBuffer(memoryStream));
Task.Run(() => SendFromBufferToSocket(socket));
}
private void ReadFromStreamToBuffer(MemoryStream stream)
{
while (true)
{
if (stream.Length > BufferSize)
{
byte[] buffer = new byte[BufferSize];
stream.Read(buffer, 0, BufferSize);
_buffer.Add(buffer);
}
}
}
private async Task SendFromBufferToSocket(Socket socket)
{
NetworkStream networkStream = new NetworkStream(socket);
foreach (var buffer in _buffer.GetConsumingEnumerable())
{
await networkStream.WriteAsync(buffer, 0, buffer.Length);
}
}
}
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Jason