B
B
BristlyStarling2016-04-11 22:46:17
ASP.NET
BristlyStarling, 2016-04-11 22:46:17

Chrome. Asp.net/PushStreamContent. Why does video streaming stop?

API:

public HttpResponseMessage Get(string id)
        {
            var video = new VideoStream(id);
            var response = Request.CreateResponse();
            response.Content = new PushStreamContent((Action<Stream, HttpContent, TransportContext>)video.WriteToStream, new MediaTypeHeaderValue("video/webm"));
            response.Content.LoadIntoBufferAsync();
            return response;
        }

Video Stream:
public async void WriteToStream(Stream outputStream, HttpContent content, TransportContext context)
        {
            try
            {
                byte[] buffer;

                var f = File.Open(_filename, FileMode.Open, FileAccess.Read);
                if (f != null)
                    buffer = new byte[f.Length];
                else
                    buffer = new byte[Int32.MaxValue];

                f.Close();

                using (var video = File.Open(_filename, FileMode.Open, FileAccess.Read))
                {
                        var length = (int)video.Length;
                        var bytesRead = 1;
                       
                        while (length > 0 && bytesRead > 0)
                        {
                            bytesRead = video.Read(buffer, 0, Math.Min(length, buffer.Length));
                            await outputStream.WriteAsync(buffer, 0, bytesRead);
                            length -= bytesRead;
                        }
                        video.Close();
                        video.Dispose();
                }
            }
            catch
            {
                throw;             
            }
            finally
            {
               outputStream.Close();
            }
        }

If the video is more than 2 meters, chrome sends a second request at the end of the video. There was a problem The remote host closed the connection. The error code is 0x80070040 Decided to increase executionTimeout.
But why is the stream retransmission not happening?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question