I have created the API in asp.net core 2.0 that returns the video file streaming Result. but in the view only play sound of video.

      [HttpGet()]
        public IActionResult Get()
        {
            string videoPath = configuration.GetValue<string>(WebHostDefaults.ContentRootKey) + "/Content/Videos/1.mp4";
            if (System.IO.File.Exists(videoPath))
            {
                FileInfo fi = new FileInfo(videoPath);
                var video = new VideoStream(videoPath);
                var response = new HttpResponseMessage()
                {
                    Content = new PushStreamContent((Action<Stream, HttpContent, TransportContext>)(video.WriteToStream),
                    new MediaTypeHeaderValue("video/mp4").MediaType)
                };

                response.Content.Headers.Add("Content-Disposition", "attachment;filename=" + fi.Name.Replace(" ", ""));
                response.Content.Headers.Add("Content-Length", video.FileLength.ToString());

                return File(response.Content.ReadAsByteArrayAsync().Result, "video/mp4");
            }
            else
            {
                return NotFound();
            }
        }

0 Answers