//Setup button is clicked public void Setup(object sender, EventArgs e) { //Determine which view to control view = (View)((Button)sender).FindForm(); //send the request message to the server rtspModel.Send(new RtspRequest { RequestType = RtspRequest.RtspRequestType.SETUP, FileName = VideoName }); //wait for the reply from the server try { var response = rtspModel.Listen(); sessionNum = response.Session; UpdateServerBox(response.ToString() + Environment.NewLine); UpdateClientBox("New RTSP State: READY" + Environment.NewLine); //disable & enable appropriate buttons view.DisableButton(View.Buttons.Setup); view.EnableButton(View.Buttons.Play); view.SetImageBoxBlack(); } catch (ArgumentException ex) { UpdateServerBox($"Error: {ex.Message}{Environment.NewLine}"); } }
//Play button is clicked public void Play(object sender, EventArgs e) { //Determine which view to control view = (View)((Button)sender).FindForm(); //send the request message to the server rtspModel.Send(new RtspRequest { RequestType = RtspRequest.RtspRequestType.PLAY, FileName = VideoName, SessionID = sessionNum }); //wait for the reply from the server try { var response = rtspModel.Listen(); UpdateServerBox(response.ToString() + Environment.NewLine); //Start UDP video thread to start receiving images if (videoTimerThread == null) { this.videoTimerThread = new Thread(Communications); videoTimerThread.IsBackground = true; //to stop all threads with application is terminated this.videoTimerThread.Start(); } UpdateClientBox("New RTSP State: PLAYING" + Environment.NewLine); //disable & enable appropriate buttons view.DisableButton(View.Buttons.Play); view.EnableButton(View.Buttons.Pause); view.EnableButton(View.Buttons.Teardowm); } catch (ArgumentException ex) { UpdateServerBox($"Error: {ex.Message}{Environment.NewLine}"); } }
//Connect button is clicked public void Connect(object sender, EventArgs e) { //Determine which view to control view = (View)((Button)sender).FindForm(); //disable the connect button view.DisableConnectBtn(); ClientPort = int.Parse(ViewClientPort); //Listen for server this.ListenForServer(); rtspModel.Send(new RtspRequest { RequestType = RtspRequest.RtspRequestType.DESCRIBE, FileName = VideoName }); //wait for the reply from the server try { var response = rtspModel.Listen(); var files = response.Content.Split(';') .Where(file => file != string.Empty) .ToArray(); UpdateVideosList(files); UpdateServerBox(response.ToString() + Environment.NewLine); UpdateClientBox("New RTSP State: CONNECTED" + Environment.NewLine); //disable & enable appropriate buttons view.EnableButton(View.Buttons.Setup); view.EnableFilesCmb(); } catch (ArgumentException ex) { UpdateServerBox($"Error: {ex.Message}{Environment.NewLine}"); } }