📄 myav.cs
字号:
this.panelSelfAV.Controls.Add(this.picLocal);
this.panelSelfAV.Controls.Add(this.pictureBox1);
this.panelSelfAV.Location = new System.Drawing.Point(123, 248);
this.panelSelfAV.Name = "panelSelfAV";
this.panelSelfAV.Size = new System.Drawing.Size(170, 134);
this.panelSelfAV.TabIndex = 45;
//
// picLocal
//
this.picLocal.BackColor = System.Drawing.Color.WhiteSmoke;
this.picLocal.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.picLocal.Location = new System.Drawing.Point(5, 8);
this.picLocal.Name = "picLocal";
this.picLocal.Size = new System.Drawing.Size(160, 120);
this.picLocal.TabIndex = 8;
this.picLocal.TabStop = false;
//
// pictureBox1
//
this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.Location = new System.Drawing.Point(0, 0);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(170, 134);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pictureBox1.TabIndex = 47;
this.pictureBox1.TabStop = false;
//
// label2
//
this.label2.AutoSize = true;
this.label2.ForeColor = System.Drawing.Color.Purple;
this.label2.Location = new System.Drawing.Point(8, 57);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(54, 17);
this.label2.TabIndex = 5;
this.label2.Text = "麦克风:";
//
// label1
//
this.label1.AutoSize = true;
this.label1.ForeColor = System.Drawing.Color.Purple;
this.label1.Location = new System.Drawing.Point(8, 20);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(42, 17);
this.label1.TabIndex = 4;
this.label1.Text = "声卡:";
//
// linkLabelReceve
//
this.linkLabelReceve.AutoSize = true;
this.linkLabelReceve.Font = new System.Drawing.Font("宋体", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.linkLabelReceve.ForeColor = System.Drawing.Color.Purple;
this.linkLabelReceve.LinkColor = System.Drawing.Color.DarkRed;
this.linkLabelReceve.Location = new System.Drawing.Point(3, 359);
this.linkLabelReceve.Name = "linkLabelReceve";
this.linkLabelReceve.Size = new System.Drawing.Size(66, 20);
this.linkLabelReceve.TabIndex = 47;
this.linkLabelReceve.TabStop = true;
this.linkLabelReceve.Text = "接收视频";
this.linkLabelReceve.Visible = false;
this.linkLabelReceve.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabelReceve_LinkClicked);
//
// linkLabelCancelAV
//
this.linkLabelCancelAV.AutoSize = true;
this.linkLabelCancelAV.Font = new System.Drawing.Font("宋体", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.linkLabelCancelAV.ForeColor = System.Drawing.Color.Purple;
this.linkLabelCancelAV.LinkColor = System.Drawing.Color.DarkRed;
this.linkLabelCancelAV.Location = new System.Drawing.Point(75, 359);
this.linkLabelCancelAV.Name = "linkLabelCancelAV";
this.linkLabelCancelAV.Size = new System.Drawing.Size(36, 20);
this.linkLabelCancelAV.TabIndex = 48;
this.linkLabelCancelAV.TabStop = true;
this.linkLabelCancelAV.Text = "取消";
this.linkLabelCancelAV.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabelCancelAV_LinkClicked);
//
// groupBox1
//
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Controls.Add(this.trackBarOut);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.trackBarIn);
this.groupBox1.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.groupBox1.ForeColor = System.Drawing.Color.Purple;
this.groupBox1.Location = new System.Drawing.Point(3, 251);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(117, 96);
this.groupBox1.TabIndex = 49;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "音量调整";
//
// timer1
//
this.timer1.Interval = 56000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// MyAV
//
this.BackColor = System.Drawing.Color.Cyan;
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.linkLabelCancelAV);
this.Controls.Add(this.linkLabelReceve);
this.Controls.Add(this.panelSelfAV);
this.Controls.Add(this.panel1);
this.Controls.Add(this.bar4);
this.Name = "MyAV";
this.Size = new System.Drawing.Size(296, 392);
((System.ComponentModel.ISupportInitialize)(this.trackBarIn)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.trackBarOut)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.bar4)).EndInit();
this.panel1.ResumeLayout(false);
this.panelSelfAV.ResumeLayout(false);
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
public void SetParameter(System.Net.IPAddress ip,int port,LanMsg.Controls.ClassMsg msg)
{
this.serverIp =ip;
this.serverPort=port;
this.msg=msg;
this.ReadyConnect();
}
public void ColseAV()//关闭当前正在进行的视频对话
{
IsAV=false;
this.linkLabelReceve.Visible=false;
try
{
this.av.AVChanel.Close();
}
catch{}
try
{
this.av.Chanel.Close();
}
catch{}
try
{
this.av.Dispose();
}
catch{}
}
private void mixer_MixerControlChange(object sender, EventArgs e)
{
this.trackBarIn.Value=this.indtl.Volume;
this.trackBarOut.Value=this.outdtl.Volume;
}
private void trackBarOut_Scroll(object sender, System.EventArgs e)
{
this.outdtl.Volume=this.trackBarOut.Value;
this.indtl.Volume=this.trackBarIn.Value;
}
public void Initialize()//初始化视频图片与sock
{
if(av!=null)this.av.Dispose();
this.av=new AV.AV(this.picLocal ,this.picRemote);
this.av.IniChanel();
}
public AV.AV AV
{
get{return this.av;}
}
private bool IsAV=false;//表示当前是否正在视频中
private void ReadyConnect()//准备连接,并告诉对方本地IP与端口,让其联接
{
if(!IsAV)
{
Initialize();
this.av.ReadyStrat(new ClassSerializers().SerializeBinary(this.msg).ToArray() ,this.serverIp ,this.serverPort);
}
else
{
this.av.AVChanel.Close();
this.av.Chanel.Close();
}
IsAV=!IsAV;
//UDP打洞
}
public void Connect(string ip,int port)//连接到对方并且开始发送AV数据
{
this.av.IniAudio();
this.av.IniVideo();
this.av.Start(ip,port);
}
public void Stop()
{
if(this.av!=null)this.av.Dispose();
}
private void timer1_Tick(object sender, System.EventArgs e)
{
this.av.UDPBurrowNat(this.serverIp ,this.serverPort );//UDP打洞
}
private void linkLabelCancelAV_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
IsAV=false;
this.linkLabelReceve.Visible=false;
try
{
this.av.AVChanel.Close();
this.av.Chanel.Close();
this.av.Dispose();
}
catch{}
this.AVCancel(this,true);//触发终止事件
}
private void linkLabelReceve_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
this.linkLabelReceve.Visible=false;
this.AVReceve(this,true);//触发AV接收事件
Initialize();//初始化视频设备
this.av.IniAudio();//初始化音频设备
this.av.IniVideo();//初始化视频设备
this.AV.BeginAV(new ClassSerializers().SerializeBinary(new LanMsg.Controls.ClassMsg(14,this.msg.ID,null)).ToArray(),this.serverIp,this.serverPort);//告诉对方可以开始视频
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -