private TcpListener client; //listen for connections #endregion Fields #region Constructors public ThreadedTcpSrvr() { //public List<Song> musicQueue = new List<Song>(); monocheck(); client = new TcpListener(8009); client.Start(); Console.WriteLine("Waiting for clients..."); while (true) { while (!client.Pending()) { if (isPlaying == false) { Program.gui.updateNP(String.Empty); } if (musicQueue.Count > 0 && isPlaying == false) { isPlaying = true; //we'll play it if(System.IO.File.Exists("currentsong.media")) { System.IO.File.Delete("currentsong.media"); } Song thisSong = musicQueue[0]; string currentSong = thisSong.song; if(System.IO.File.Exists(thisSong.song)) { System.IO.File.Move(thisSong.song, "currentsong.media"); } string currentPath = System.IO.Path.GetFullPath(currentSong); if (System.IO.File.Exists("mplayer.exe")) { mplaying.StartInfo.FileName = "mplayer.exe"; } else { mplaying.StartInfo.FileName = "mplayer"; } mplaying.StartInfo.Arguments = " " + "currentsong.media" + " "; mplaying.StartInfo.UseShellExecute = false; mplaying.StartInfo.CreateNoWindow = true; //mplaying.StartInfo.RedirectStandardError = true; //mplaying.StartInfo.RedirectStandardOutput = true; BackgroundWorkerExecProcess(mplaying); //System.Console.WriteLine("now playing " + thisSong.info); Program.gui.updateNP(thisSong.info.Replace('\n', '\t')); //deleting file previous musicQueue.RemoveAt(0); } String queue = String.Empty; foreach (Song song in musicQueue) { queue += song.info.Replace('\n', '\t') + "\n"; } Program.gui.updateQueue(queue); Thread.Sleep(1000); } ConnectionThread newconnection = new ConnectionThread(); newconnection.threadListener = this.client; Thread newthread = new Thread(new ThreadStart(newconnection.HandleConnection)); newthread.Start(); while (newthread.IsAlive) { } byte[] mySong = newconnection.song; if (mySong != null) { int mysongSID = GetSID(); ByteArrayToFile(SID + ".media", mySong); string mySongInfo = GetSongInfo(SID + ".media", SID); Song song = new Song(mySongInfo, SID + ".media", mysongSID); musicQueue.Add(song); } } }
public ThreadedTcpSrvr() { //public List<Song> musicQueue = new List<Song>(); monocheck(); client = new TcpListener(8009); client.Start(); Console.WriteLine("Waiting for clients..."); while (true) { while (!client.Pending()) { if (isPlaying == false) { Program.gui.updateNP(String.Empty); } if (musicQueue.Count > 0 && isPlaying == false) { isPlaying = true; //we'll play it if (System.IO.File.Exists("currentsong.media")) { System.IO.File.Delete("currentsong.media"); } Song thisSong = musicQueue[0]; string currentSong = thisSong.song; if (System.IO.File.Exists(thisSong.song)) { System.IO.File.Move(thisSong.song, "currentsong.media"); } string currentPath = System.IO.Path.GetFullPath(currentSong); if (System.IO.File.Exists("mplayer.exe")) { mplaying.StartInfo.FileName = "mplayer.exe"; } else { mplaying.StartInfo.FileName = "mplayer"; } mplaying.StartInfo.Arguments = " " + "currentsong.media" + " "; mplaying.StartInfo.UseShellExecute = false; mplaying.StartInfo.CreateNoWindow = true; //mplaying.StartInfo.RedirectStandardError = true; //mplaying.StartInfo.RedirectStandardOutput = true; BackgroundWorkerExecProcess(mplaying); //System.Console.WriteLine("now playing " + thisSong.info); Program.gui.updateNP(thisSong.info.Replace('\n', '\t')); //deleting file previous musicQueue.RemoveAt(0); } String queue = String.Empty; foreach (Song song in musicQueue) { queue += song.info.Replace('\n', '\t') + "\n"; } Program.gui.updateQueue(queue); Thread.Sleep(1000); } ConnectionThread newconnection = new ConnectionThread(); newconnection.threadListener = this.client; Thread newthread = new Thread(new ThreadStart(newconnection.HandleConnection)); newthread.Start(); while (newthread.IsAlive) { } byte[] mySong = newconnection.song; if (mySong != null) { int mysongSID = GetSID(); ByteArrayToFile(SID + ".media", mySong); string mySongInfo = GetSongInfo(SID + ".media", SID); Song song = new Song(mySongInfo, SID + ".media", mysongSID); musicQueue.Add(song); } } } //does EVERYTHING, I should modularize this