|
10 | 10 | static byte[] buff = new byte[4096];
|
11 | 11 | static int read;
|
12 | 12 |
|
| 13 | + LibraryLoader.Instance.LoadDllDirectory(); |
| 14 | + |
13 | 15 | string filename = "";
|
14 | 16 | if (args.Count() > 0)
|
15 | 17 | filename = args[0];
|
16 |
| - else return; |
17 |
| - |
18 |
| - icecast = new Libshout(); |
19 |
| - icecast.setProtocol(0); |
20 |
| - icecast.setHost("127.0.0.1"); |
21 |
| - icecast.setPort(8000); |
22 |
| - icecast.setPassword("hackme"); |
23 |
| - icecast.setFormat(Libshout.FORMAT_MP3); |
24 |
| - icecast.setPublic(true); |
25 |
| - icecast.setName("radio"); |
26 |
| - icecast.setMount("/live"); |
27 |
| - icecast.open(); |
28 |
| - |
29 |
| - //подключились |
30 |
| - if (icecast.isConnected()) |
31 |
| - Console.WriteLine("Connect!"); |
32 |
| - else Console.WriteLine(icecast.GetError()); |
33 |
| - |
34 |
| - //читаем файл |
| 18 | + else filename = Path.Combine(Environment.CurrentDirectory, "music.mp3"); |
| 19 | + |
| 20 | + //set parameters |
| 21 | + icecast = new Libshout(); |
| 22 | + icecast.Protocol = Libshout.SHOUT_PROTOCOL.SHOUT_PROTOCOL_HTTP; |
| 23 | + icecast.Host = "127.0.0.1"; |
| 24 | + icecast.Port=8000; |
| 25 | + icecast.Name = "my super radio"; |
| 26 | + icecast.Password="hackme"; |
| 27 | + icecast.Mount= "/example.ogg"; |
| 28 | + icecast.User= "source";//or "admin" |
| 29 | + icecast.Format=Libshout.SHOUT_FORMAT.SHOUT_FORMAT_MP3; |
| 30 | + |
| 31 | + //try open connection |
| 32 | + icecast.Open(); |
| 33 | + |
| 34 | + if (!icecast.IsConnected()) |
| 35 | + { |
| 36 | + Console.WriteLine(icecast.GetError()); |
| 37 | + return; |
| 38 | + } |
| 39 | + |
| 40 | + Console.WriteLine("Connect!"); |
| 41 | + |
| 42 | + //read file |
35 | 43 | BinaryReader reader = new BinaryReader(File.Open(filename, FileMode.Open));
|
| 44 | + var lenght = reader.BaseStream.Length; |
36 | 45 | int total = 0;
|
| 46 | + var cursor = Console.GetCursorPosition(); |
37 | 47 | while (true)
|
38 | 48 | {
|
39 |
| - //читаем буфер |
40 |
| - read = reader.Read(buff, 0, buff.Length); |
| 49 | + //read buffer b |
| 50 | + read = reader.Read(buff, 0, buff.Length); |
41 | 51 | total = total + read;
|
42 | 52 |
|
43 |
| - Console.WriteLine("Position: "+reader.BaseStream.Position); |
44 |
| - //если прочитан не весь, то передаем |
| 53 | + Console.SetCursorPosition(0, cursor.Top); |
| 54 | + Console.WriteLine($"Position: {(total / (double) lenght) * 100:00.00} %"); |
| 55 | + //if not end, then send buffer to icecast |
45 | 56 | if (read > 0)
|
46 | 57 | {
|
47 |
| - icecast.send(buff, read); //пауза, синхронизация внутри метода |
| 58 | + icecast.Send(buff, read); //sync inside method |
48 | 59 | }
|
49 |
| - else break; //уходим |
50 |
| - |
| 60 | + else break; |
51 | 61 | }
|
52 | 62 |
|
53 | 63 | Console.WriteLine("Done!");
|
54 | 64 | Console.ReadKey(true);
|
55 |
| - icecast.close(); |
| 65 | + icecast.Close(); |
56 | 66 | }
|
57 | 67 |
|
0 commit comments