Download Logo

Video streaming in ASP.NET Core

Video Streaming Implementation Create One Controller CLass and Paste below code in side that class. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 [HttpGet("{fileName}")] public IActionResult GetMedia(string fileName) { var filePath = _mediaService.GetMediaFilePath(fileName); if (!System.IO.File.Exists(filePath)) { return NotFound(); } var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read); var mimeType = "video/mp4"; var fileInfo = new FileInfo(filePath); long totalLength = fileInfo.Length; long start = 0; long end = totalLength - 1; if (Request.Headers.ContainsKey("Range")) { var range = Request.Headers["Range"].ToString(); var rangeSplit = range.Replace("bytes=", "").Split('-'); start = long.Parse(rangeSplit[0]); if (rangeSplit.Length > 1 && !string.IsNullOrEmpty(rangeSplit[1])) end = long.Parse(rangeSplit[1]); } var contentLength = end - start + 1; var responseStream = new MemoryStream(); fileStream.Seek(start, SeekOrigin.Begin); fileStream.CopyTo(responseStream, (int)contentLength); responseStream.Seek(0, SeekOrigin.Begin); Response.StatusCode = (int)HttpStatusCode.PartialContent; Response.Headers.AcceptRanges = "bytes"; Response.Headers.ContentLength = contentLength; Response.Headers.ContentType = "video/mp4"; Response.Headers.ContentRange = $"bytes {start}-{end}/{totalLength}"; return new FileStreamResult(responseStream, mimeType); }

August 3, 2024 · 1 min · 170 words · PrashantUnity
Download Logo

Auto clicker in C#

Implementation in .NET Console Project 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 using System.Runtime.InteropServices; namespace MouseClicker; public class Program { [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)] static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo); private const int MOUSEEVENTF_LEFTDOWN = 0x02; private const int MOUSEEVENTF_LEFTUP = 0x04; private const int MOUSEEVENTF_RIGHTDOWN = 0x08; private const int MOUSEEVENTF_RIGHTUP = 0x10; public static int Main(string[] args) { int count = 0; while(count++<10000) { DoMouseClick(); } return 0; } public static void DoMouseClick() { mouse_event(MOUSEEVENTF_LEFTDOWN , 0, 0, 0, 0); mouse_event( MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); } }

July 12, 2024 · 1 min · 120 words · PrashantUnity
Cover Logo

IndexNow