Skip to content

simple libshout wrapper for C#

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

Zerpico/libShout-csharp

Repository files navigation

libShout-csharp

Привязка к libShout на языке C#

Пример испльзования:

static void Main(string[] args)
{
    static Libshout icecast;
    static byte[] buff = new byte[4096];
    static int read;
    
    LibraryLoader.Instance.LoadDllDirectory();

    string filename = "";
    if (args.Count() > 0)
        filename = args[0];
    else filename = Path.Combine(Environment.CurrentDirectory, "music.mp3");
   
    //set parameters
    icecast = new Libshout();            
    icecast.Protocol = Libshout.SHOUT_PROTOCOL.SHOUT_PROTOCOL_HTTP;
    icecast.Host = "127.0.0.1";
    icecast.Port=8000;
    icecast.Name = "my super radio";
    icecast.Password="hackme";
    icecast.Mount= "/example.ogg";
    icecast.User= "source";//or "admin"
    icecast.Format=Libshout.SHOUT_FORMAT.SHOUT_FORMAT_MP3;

	//try open connection
    icecast.Open();
   
    if (!icecast.IsConnected())
	{
		Console.WriteLine(icecast.GetError());
		return;
	}
	
	Console.WriteLine("Connect!");

    //read file
    BinaryReader reader = new BinaryReader(File.Open(filename, FileMode.Open));
    var lenght = reader.BaseStream.Length;
    int total = 0;
    var cursor = Console.GetCursorPosition();
    while (true)
    {
        //read buffer b
        read = reader.Read(buff, 0, buff.Length);
        total = total + read;

        Console.SetCursorPosition(0, cursor.Top);
        Console.WriteLine($"Position:  {(total / (double) lenght) * 100:00.00} %");
        //if not end, then send buffer to icecast 
        if (read > 0)
        {
            icecast.Send(buff, read);  //sync inside method
        }
        else break;  
    }

    Console.WriteLine("Done!");
    Console.ReadKey(true);
    icecast.Close();          
}

About

simple libshout wrapper for C#

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages