Exemple #1
0
        static void Main(string[] args)
        {
            //Set directory where app should look for FFmpeg
            //FFmpeg.ExecutablesPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "FFmpeg");
            //Get latest version of FFmpeg. It's great idea if you don't know if you had installed FFmpeg.
            //await FFmpeg.GetLatestVersion();



            clientList = new List <client_IPEndPoint>()
            {
                new client_IPEndPoint()
                {
                    ID_client = "20154023", On = true, NumSend = 1
                },
                new client_IPEndPoint()
                {
                    ID_client = "20164023", On = false
                },
                new client_IPEndPoint()
                {
                    ID_client = "00000001", On = true
                },
                new client_IPEndPoint()
                {
                    ID_client = "00000002", On = true
                },
                new client_IPEndPoint()
                {
                    ID_client = "00000003", On = true
                },
                new client_IPEndPoint()
                {
                    ID_client = "00000004", On = true
                },
                new client_IPEndPoint()
                {
                    ID_client = "00000005", On = true
                },
                new client_IPEndPoint()
                {
                    ID_client = "00000006", On = true
                },
                new client_IPEndPoint()
                {
                    ID_client = "00000007", On = true
                },
                new client_IPEndPoint()
                {
                    ID_client = "00000008", On = true
                },
                new client_IPEndPoint()
                {
                    ID_client = "00000009", On = true
                },
                new client_IPEndPoint()
                {
                    ID_client = "sim", On = true, NumSend = 1
                },
            };

            string curPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            string subPath = "converted"; // Your code goes here

            subPath = Path.Combine(curPath, subPath);

            /*
             * //check if it is exits delete
             * //if (Directory.Exists(subPath)) Directory.Delete(subPath, true);
             *
             * //Directory.CreateDirectory(subPath); //create*/

            //ffmpeg.exe -i E:\b1.mp3 -codec:a libmp3lame -b:a 48k -ac 1 -ar 24000 D:\b1mono.mp3
            bool   converterDone         = false;
            UInt64 unique_song_ID        = 0;
            List <song_name_id> listSong = new List <song_name_id>();
            Thread nethos = new Thread(() =>
            {
                ProcessStartInfo startInfo = new ProcessStartInfo()
                {
                    FileName       = "ffmpeg",
                    CreateNoWindow = false,
                    //Arguments = $"-y -i {soundList[0].FilePath} -codec:a libmp3lame -b:a 8k -ac 1 -ar 24000 {Path.Combine(curPath, "b18k.mp3")}",
                    UseShellExecute = false
                };

                DirectoryInfo di = new DirectoryInfo(curPath);
                foreach (FileInfo file in di.GetFiles())
                {
                    if (file.Extension == ".mp3")
                    {
                        listSong.Add(new song_name_id
                        {
                            uint64_id    = unique_song_ID,
                            main_name    = file.Name,
                            convert_name = unique_song_ID.ToString()
                        });
                        file.MoveTo(Path.Combine(curPath, unique_song_ID.ToString() + file.Extension), true);
                        unique_song_ID++;
                        //reserve if unique_song_ID == MAX UINT64 have 2 option

                        /*
                         * 1. delete all song converted with unique_song_ID < MAX, not good
                         * 2. rechange all unique to start from 0
                         */
                        Process proc        = new Process();
                        startInfo.Arguments = $"-y -i {Path.Combine(curPath, file.Name)} -b:a 48k -ac 1 -ar 24000 {Path.Combine(subPath, file.Name)}";
                        proc.StartInfo      = startInfo;
                        proc.Start();
                        proc.WaitForExit();
                        proc.Close();
                    }
                }
                converterDone = true;
            });

            //check if it is not exist create and convert
            if (!Directory.Exists(subPath))
            {
                Directory.CreateDirectory(subPath); //create*/
                nethos.Start();
            }
            else
            {
                converterDone = true;
            }

            //wait until converter is done
            while (true)
            {
                if (converterDone)
                {
                    break;
                }
                Thread.Sleep(1000);
            }
            Console.WriteLine("Done converter");

            List <soundTrack> soundList = new List <soundTrack>();
            DirectoryInfo     di        = new DirectoryInfo(subPath);

            foreach (FileInfo file in di.GetFiles())
            {
                if (file.Extension == ".mp3")
                {
                    soundList.Add(new soundTrack()
                    {
                        FilePath = Path.Combine(subPath, file.Name)
                    });
                }
            }

            //launch
            UDPsocket udpSocket = new UDPsocket();

            udpSocket.launchUDPsocket(soundList, clientList);

            control(udpSocket);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            //Console.WriteLine("Hello World!");

            clientList = new List <client_IPEndPoint>()
            {
                new client_IPEndPoint()
                {
                    ID_client = "20154023", On = true, NumSend = 1
                },
                new client_IPEndPoint()
                {
                    ID_client = "20164023", On = false
                },
                new client_IPEndPoint()
                {
                    ID_client = "00000001", On = true
                },
                new client_IPEndPoint()
                {
                    ID_client = "00000002", On = true
                },
                new client_IPEndPoint()
                {
                    ID_client = "00000003", On = true
                },
                new client_IPEndPoint()
                {
                    ID_client = "00000004", On = true
                },
                new client_IPEndPoint()
                {
                    ID_client = "00000005", On = true
                },
                new client_IPEndPoint()
                {
                    ID_client = "00000006", On = true
                },
                new client_IPEndPoint()
                {
                    ID_client = "00000007", On = true
                },
                new client_IPEndPoint()
                {
                    ID_client = "00000008", On = true
                },
                new client_IPEndPoint()
                {
                    ID_client = "00000009", On = true
                },
                new client_IPEndPoint()
                {
                    ID_client = "000000010", On = true
                },
            };

            List <soundTrack> soundList = new List <soundTrack>()
            {
                new soundTrack()
                {
                    FilePath = @"E:\bai111.mp3"
                },
                new soundTrack()
                {
                    FilePath = @"E:\bai124k.mp3"
                }
            };

            List <soundTrack> soundListServer = new List <soundTrack>()
            {
                new soundTrack()
                {
                    FilePath = "bai1.mp3"
                },
                new soundTrack()
                {
                    FilePath = "bai2.mp3"
                },
                new soundTrack()
                {
                    FilePath = "bai3.mp3"
                }
                //new soundTrack(){ FilePath = "LoveIsBlue.mp3"}
            };

            UDPsocket udpSocket = new UDPsocket();
            //var _status = udpSocket.Status; //get status (PLAY, PAUSE, STOP)
            string filePath;
            string filePath1 = @"E:/bai111.mp3";
            string filePath2 = "bai111.mp3";

            Console.Write("Server  1: Local, 2: online: ");
            char ch = Console.ReadKey().KeyChar;

            if (ch == '1')
            {
                filePath = filePath1;
            }
            else
            {
                filePath  = filePath2;
                soundList = soundListServer;
            }
            //byte[] mp3_buff = File.ReadAllBytes(filePath).Skip(237).ToArray();
            ////MP3_ADU mp3file = new MP3_ADU(mp3_buff, mp3_buff.Length);
            ////int numFrame = 0;

            //ADU_frame adufile = new ADU_frame(mp3_buff, mp3_buff.Length);
            //int aduNumFrame = 0;

            ////FileStream stream = new FileStream(@"E:\test10.mp3", FileMode.Append);

            //List<byte[]> aduFrameList = new List<byte[]>();
            //while (true)
            //{
            //    byte[] aduframe = adufile.ReadNextADUFrame();
            //    if (aduframe != null)
            //    {
            //        aduNumFrame++;
            //        //AppendAllBytes(@"E:\adu.mp3", aduframe);
            //        //stream.Write(aduframe, 0, aduframe.Length);
            //        aduFrameList.Add(aduframe);
            //    }
            //    else
            //    {
            //        break;
            //    }
            //}
            //stream.Close();

            //launch
            //udpSocket.launchUDPsocket(soundList, clientList);
            udpSocket.launchUDPsocket(soundList, clientList);
            //create UDP socket listen from client
            udpSocket.UDPsocketListen();
            //create UDP socket for sending mp3 frame to client
            udpSocket.UDPsocketSend();
            //control(udpSocket);
        }
Exemple #3
0
        static void control(UDPsocket udpSocket)
        {
            var statusNow   = udpSocket.Status;
            int currentTime = udpSocket.TimePlaying_song_s; //second
            int duration    = 0;
            int song_ID     = 0;                            //order of song in soundList

            Console.Title          = "Project truyen thanh!!!";
            Console.OutputEncoding = Encoding.UTF8;
            int cursor = Console.CursorTop;

            Console.WriteLine("Status: {0}", statusNow);                  //line 2-7
            Console.WriteLine("Song: {0}", song_ID);                      //line 3-6
            Console.WriteLine("Current time play: ");                     //line 4-19
            Console.WriteLine("Duration: 0:0");                           //line 5-10
            Console.WriteLine("Send time: {0,2}", clientList[0].NumSend); //line 6-11

            Console.WriteLine("Lệnh:");
            Console.WriteLine(" 1:Play/ Resume");
            Console.WriteLine(" 2:Pause");
            Console.WriteLine(" 3:Next");
            Console.WriteLine(" 4:Previous");
            Console.WriteLine(" 5:Stop");
            Console.WriteLine(" 6:Increase send time");
            Console.WriteLine(" 7:Decrease send time");
            Console.Write("Nhập số tương ứng để tiến hành điều khiển: "); //line 10


            //thread update status every 1s
            Thread displayStatus = new Thread(() =>
            {
                while (true)
                {
                    if (statusNow != udpSocket.Status)
                    {
                        statusNow = udpSocket.Status;
                        Console.SetCursorPosition(8, cursor);
                        Console.Write(statusNow + "    ");
                    }
                    if (song_ID != udpSocket.SongID)
                    {
                        song_ID = udpSocket.SongID;
                        Console.SetCursorPosition(6, cursor + 1);
                        Console.Write(song_ID);
                    }

                    currentTime = udpSocket.TimePlaying_song_s;
                    Console.SetCursorPosition(19, cursor + 2);
                    Console.Write("{0,2}:{1,2}", currentTime / 60, currentTime % 60);

                    if (duration != udpSocket.Duration_song_s)
                    {
                        duration = udpSocket.Duration_song_s;
                        Console.SetCursorPosition(10, cursor + 3);
                        Console.Write("{0,2}:{1,2}", duration / 60, duration % 60);
                    }
                    //Console.SetCursorPosition(43, 9);
                    Thread.Sleep(1000);
                }
            });

            displayStatus.Priority = ThreadPriority.BelowNormal;
            displayStatus.Start();

            //thread control for test
            Thread readControl = new Thread(() =>
            {
                while (true)
                {
                    //Console.SetCursorPosition(43, 9);
                    var control = Console.ReadKey(true);
                    switch (control.KeyChar)
                    {
                    case '1':                                        //play/resume
                        //
                        if (statusNow == UDPsocket.status_enum.STOP) //play
                        {
                            udpSocket.UDPsocketSend();
                        }
                        else if (statusNow == UDPsocket.status_enum.PAUSE) //resume
                        {
                            udpSocket.controlThreadSend(2);                //resume
                        }
                        break;

                    case '2':                                        //pause
                        //
                        if (statusNow == UDPsocket.status_enum.PLAY) //play
                        {
                            udpSocket.controlThreadSend(1);          //pause
                        }
                        break;

                    case '3':     //next
                        if (statusNow != UDPsocket.status_enum.STOP)
                        {
                            udpSocket.controlThreadSend(3);
                            //udpSocket.ClientList[0].NumSend = 2;
                        }
                        break;

                    case '4':     //previous
                        if (statusNow != UDPsocket.status_enum.STOP)
                        {
                            udpSocket.controlThreadSend(4);
                        }
                        break;

                    case '5':     //stop
                        //
                        if (statusNow != UDPsocket.status_enum.STOP)
                        {
                            udpSocket.controlThreadSend(5);    //stop
                        }
                        break;

                    case '6':     //increase send time
                        clientList[0].NumSend++;
                        Console.SetCursorPosition(11, cursor + 4);
                        Console.Write("{0,2}", clientList[0].NumSend);
                        break;

                    case '7':     //decrease send time
                        if (clientList[0].NumSend > 1)
                        {
                            clientList[0].NumSend--;
                            Console.SetCursorPosition(11, cursor + 4);
                            Console.Write("{0,2}", clientList[0].NumSend);
                        }
                        break;
                    }
                    0
                }
            });

            readControl.Priority = ThreadPriority.Lowest;
            readControl.Start();
        }
        static void Main(string[] args)
        {
            //Console.WriteLine("Hello World!");

            clientList = new List <client_IPEndPoint>()
            {
                new client_IPEndPoint()
                {
                    ID_client = "20154023", On = true, NumSend = 1
                },
                new client_IPEndPoint()
                {
                    ID_client = "20164023", On = false
                },
                new client_IPEndPoint()
                {
                    ID_client = "00000001", On = true
                },
                new client_IPEndPoint()
                {
                    ID_client = "00000002", On = true
                },
                new client_IPEndPoint()
                {
                    ID_client = "00000003", On = true
                },
                new client_IPEndPoint()
                {
                    ID_client = "00000004", On = true
                },
                new client_IPEndPoint()
                {
                    ID_client = "00000005", On = true
                },
                new client_IPEndPoint()
                {
                    ID_client = "00000006", On = true
                },
                new client_IPEndPoint()
                {
                    ID_client = "00000007", On = true
                },
                new client_IPEndPoint()
                {
                    ID_client = "00000008", On = true
                },
                new client_IPEndPoint()
                {
                    ID_client = "00000009", On = true
                },
                new client_IPEndPoint()
                {
                    ID_client = "000000010", On = true
                },
            };
            List <soundTrack> soundList;
            List <soundTrack> soundListLocal = new List <soundTrack>()
            {
                new soundTrack()
                {
                    FilePath = @"E:\truyenthanhproject\mp3\bai2.mp3"
                },
                new soundTrack()
                {
                    FilePath = @"E:\truyenthanhproject\mp3\bai3.mp3"
                },
                //new soundTrack(){ FilePath = @"E:\truyenthanhproject\mp3\xeDap.mp3"}
            };

            List <soundTrack> soundListServer = new List <soundTrack>()
            {
                new soundTrack()
                {
                    FilePath = "bai2.mp3"
                },
                new soundTrack()
                {
                    FilePath = "bai3.mp3"
                }
                //new soundTrack(){ FilePath = "LoveIsBlue.mp3"}
            };

            Console.Write("Choose 1-Local, 2-Cloud: ");
            char c = Console.ReadKey().KeyChar;

            if (c == '1')
            {
                soundList = soundListLocal;
            }
            else
            {
                soundList = soundListServer;
            }

            UDPsocket udpSocket = new UDPsocket();

            //var _status = udpSocket.Status; //get status (PLAY, PAUSE, STOP)

            //launch
            //udpSocket.launchUDPsocket(soundList, clientList);
            udpSocket.launchUDPsocket(soundList, clientList);
            //create UDP socket listen from client
            udpSocket.UDPsocketListen();
            //create UDP socket for sending mp3 frame to client
            udpSocket.UDPsocketSend();
            control(udpSocket);
        }