/// <summary> /// 请求视频聊天 /// </summary> private void toolStripButton2_Click(object sender, EventArgs e) { try { //打开视频窗口 vc = new VideoConnection(userName, listBox1.SelectedItem.ToString(), multimediaManager); vc.OpenVideoViewer(ViewerType.VideoView, true); vc.Show(); //发送请求消息给对方 List <string> list = new List <string>(); list.Add(listBox1.SelectedItem.ToString()); list.Add(InformationTypes.VideoRequest.ToString()); dataProcessing.sendData(16, list); toolStripButton2.Enabled = false; soundReming(); } catch (Exception ee) { MessageBox.Show(ee.Message); } }
/// <summary> /// 处理消息 /// </summary> public void HandleInformation(string friendName, string informationType, string message) { if (this.InvokeRequired) { this.Invoke(new CbGeneric <string, string, string>(this.HandleInformation), friendName, informationType, message); } else { #region //语音请求 if (int.Parse(informationType) == InformationTypes.SoundRequest) { sendRequestName = friendName; if (listBox1.SelectedItem.ToString() == friendName) { soundRequest = new SoundRequest(userName, friendName, multimediaManager); soundRequest.Show(); soundReming(); return; } else { for (int i = 0; i < listBox1.Items.Count; i++) { if (listBox1.Items[i].ToString().Trim() == friendName) { listBox1.SelectedIndex = i; soundRequest = new SoundRequest(userName, friendName, multimediaManager); soundRequest.Show(); soundReming(); return; } } } } #endregion #region //接受语音 if (int.Parse(informationType) == InformationTypes.SoundReceive) { axWindowsMediaPlayer1.Ctlcontrols.stop();//停止视频语音聊天 sound.ConnectSound(); return; } #endregion #region //拒绝语音 if (int.Parse(informationType) == InformationTypes.SoundReject) { axWindowsMediaPlayer1.Ctlcontrols.stop();//停止视频语音聊天 sound.Close(); if (sound.Disposing || sound.IsDisposed) { richTextBox1.SelectionAlignment = HorizontalAlignment.Center; richTextBox1.AppendText("对方拒绝接受语音\n"); toolStripButton3.Enabled = true; return; } richTextBox1.SelectionAlignment = HorizontalAlignment.Center; richTextBox1.AppendText("对方拒绝接受语音\n"); toolStripButton3.Enabled = true; return; } #endregion #region 关闭语音 if (int.Parse(informationType) == InformationTypes.CloseSound) { axWindowsMediaPlayer1.Ctlcontrols.stop(); if (sound != null) { if (friendName != sendRequestName) { sound.CloseVideoFunction(int.Parse(informationType), null); richTextBox1.SelectionAlignment = HorizontalAlignment.Center; richTextBox1.AppendText(message); toolStripButton3.Enabled = true; return; } else { sound.CloseVideoFunction(-1, null); richTextBox1.SelectionAlignment = HorizontalAlignment.Center; richTextBox1.AppendText(message); toolStripButton3.Enabled = true; return; } } else { if (friendName != sendRequestName) { soundRequest.CloseVideoFunction(int.Parse(informationType), null); richTextBox1.SelectionAlignment = HorizontalAlignment.Center; richTextBox1.AppendText(message); toolStripButton3.Enabled = true; return; } else { soundRequest.CloseVideoFunction(-1, null); richTextBox1.SelectionAlignment = HorizontalAlignment.Center; richTextBox1.AppendText(message); toolStripButton3.Enabled = true; return; } } } #endregion #region //视频请求 if (int.Parse(informationType) == InformationTypes.VideoRequest) { vc = new VideoConnection(userName, friendName, multimediaManager); if (vc.HaveVideo) { return; } if (listBox1.SelectedItem.ToString() == friendName) { vc.OpenVideoViewer(ViewerType.VideoRequest, false); vc.Show(); soundReming(); return; } else { for (int i = 0; i < listBox1.Items.Count; i++) { if (listBox1.Items[i].ToString().Trim() == friendName) { listBox1.SelectedIndex = i; vc.OpenVideoViewer(ViewerType.VideoRequest, false); vc.Show(); soundReming(); return; } } } } #endregion #region 接受视频 if (int.Parse(informationType) == InformationTypes.VideoReceive) { axWindowsMediaPlayer1.Ctlcontrols.stop();//停止视频语音聊天 vc.ConnectVideo(); return; } #endregion #region 拒绝视频 if (int.Parse(informationType) == InformationTypes.VideoReject) { axWindowsMediaPlayer1.Ctlcontrols.stop();//停止视频语音聊天 vc.CloseVideoViewer(); if (vc.Disposing || vc.IsDisposed) { richTextBox1.SelectionAlignment = HorizontalAlignment.Center; richTextBox1.AppendText("对方拒绝接受视频\n"); toolStripButton2.Enabled = true; return; } richTextBox1.SelectionAlignment = HorizontalAlignment.Center; richTextBox1.AppendText("对方拒绝接受视频\n"); toolStripButton2.Enabled = true; return; } #endregion #region 关闭视频 if (int.Parse(informationType) == InformationTypes.CloseVideo) { if (vc != null) { vc.CloseVideoFunction(-1, null); richTextBox1.SelectionAlignment = HorizontalAlignment.Center; richTextBox1.AppendText("对方挂断了视频\n"); toolStripButton2.Enabled = true; axWindowsMediaPlayer1.Ctlcontrols.stop(); } return; } #endregion #region 对方网络中断,关闭视频 if (int.Parse(informationType) == InformationTypes.NetReasonCloseVideo) { vc.CloseVideoFunction(-1, null); richTextBox1.SelectionAlignment = HorizontalAlignment.Center; richTextBox1.AppendText("网络中断,视频终止\n"); toolStripButton2.Enabled = true; axWindowsMediaPlayer1.Ctlcontrols.stop(); return; } #endregion } }