/// <summary> /// Operatin is syncrous so we can associate client with thread but shood to find way to do it though http context or smth same /// </summary> /// <param name="inputStream"></param> /// <param name="outputStream"></param> /// <param name="start"></param> /// <param name="end"></param> private static void CreatePartialContent(Stream outputStream, long position) { PlayerConnection.Initialize(); PlayerConnection.Play(); bool isFirstPacket = position == 0; DateTime lastSend = DateTime.MinValue; while (PlayerConnection.LastSeconds.Count < 3) { Thread.Sleep(1000); } while (true) { try { if (isFirstPacket) { outputStream.Write(PlayerConnection.Header, 0, PlayerConnection.Header.Length); isFirstPacket = false; } Thread.Sleep(950); int nextPacketIndex = PlayerConnection.LastSeconds.FindIndex(t => t.Key > lastSend); // we was created a spare time for the client if (nextPacketIndex == -1) { continue; } outputStream.Write(PlayerConnection.LastSeconds[nextPacketIndex].Value, 0, PlayerConnection.LastSeconds[nextPacketIndex].Value.Length); lastSend = PlayerConnection.LastSeconds[nextPacketIndex].Key; //Debug.WriteLine("Contetn pushed: " + DateTime.Now.ToString("mm:ss.FFF") + ", thread: " + Thread.CurrentThread.ManagedThreadId); } catch (System.Web.HttpException e) { Debug.WriteLine(e.ToString()); fs?.Close(); break; } catch (Exception e) { Debug.Write(e); fs?.Close(); break; } } }