update
This commit is contained in:
10
MySolution/HttpStreamingApp/HttpStreamingApp.csproj
Normal file
10
MySolution/HttpStreamingApp/HttpStreamingApp.csproj
Normal file
@@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
46
MySolution/HttpStreamingApp/Program.cs
Normal file
46
MySolution/HttpStreamingApp/Program.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System.Net;
|
||||
|
||||
namespace HttpStreamingApp
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Thread serverThread = new Thread(new ThreadStart(StartServer));
|
||||
serverThread.Start();
|
||||
Console.WriteLine("HTTP Server start.");
|
||||
|
||||
Console.ReadKey();
|
||||
serverThread.Abort();
|
||||
}
|
||||
|
||||
static void StartServer()
|
||||
{
|
||||
using (var listener = new HttpListener())
|
||||
{
|
||||
listener.Prefixes.Add("http://127.0.0.1:9879/");
|
||||
listener.Start();
|
||||
|
||||
while (true)
|
||||
{
|
||||
var context = listener.GetContext();
|
||||
var response = context.Response;
|
||||
|
||||
response.ContentType = "audio/mpeg";
|
||||
using (var stream = new FileStream("./audio.mp3", FileMode.Open))
|
||||
{
|
||||
byte[] buffer = new byte[64 *1024];
|
||||
int bytesRead = 0;
|
||||
while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) > 0)
|
||||
{
|
||||
response.OutputStream.Write(buffer, 0, bytesRead);
|
||||
response.OutputStream.Flush();
|
||||
}
|
||||
}
|
||||
|
||||
response.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user