View large video with ASP.net

0

I found an ASP code using Web Api to display videos, but it does not work for large videos (like a 100MB I have). I already tried changing the buffer number and it did not work.

Controller:

public class PlayController :ApiController 
    {
        public HttpResponseMessage GetVideoContent()
        {
            var httpResponce = Request.CreateResponse();
            httpResponce.Content = new PushStreamContent((Action<Stream, HttpContent, TransportContext>)WriteContentToStream);
            return httpResponce;
        }

        private async void WriteContentToStream(Stream outputStream, HttpContent content, TransportContext transportContent)
        { //abre arquivo e faz stream
            try
            {
                var filePath = HttpContext.Current.Server.MapPath("~/Caso1.mp4");
                int bufferSize = 40194304; // 65536, 4096, 67108864 
                byte[] buffer = new byte[bufferSize];
                using (var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    int totalSize = (int)fileStream.Length;
                    while (totalSize > 0) // enquanto total do arquivo for maior que zero
                    {
                        int count = totalSize > bufferSize ? bufferSize : totalSize;
                        int sizeOfReadedBuffer = fileStream.Read(buffer, 0, count);
                        await outputStream.WriteAsync(buffer, 0, sizeOfReadedBuffer);
                        totalSize -= sizeOfReadedBuffer; // subtraio o que já escrevi

                    }
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                outputStream.Close();
            }
            // throw new NotImplementedException();
        }
    }

HTML:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>Video Stream</title>
</head>
<body>

    <video id="video" class="dtm-video-element" preload="auto">
        <source src="api/Play" type="video/mp4" />
    </video>

</body>
</html>

What is happening is that it worked for a small video (5 seconds and 5MB), but not for larger files. Missing anything in the code? I searched the internet and found Silverlight (use Smooth Streaming), but my application is Asp.

    
asked by anonymous 29.01.2018 / 19:41

0 answers