📄 myav.cs
字号:
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(53, 12);
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(41, 12);
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, ((byte)(134)));
this.linkLabelReceve.ForeColor = System.Drawing.Color.Purple;
this.linkLabelReceve.LinkColor = System.Drawing.Color.DarkRed;
this.linkLabelReceve.Location = new System.Drawing.Point(3, 332);
this.linkLabelReceve.Name = "linkLabelReceve";
this.linkLabelReceve.Size = new System.Drawing.Size(67, 15);
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, ((byte)(134)));
this.linkLabelCancelAV.ForeColor = System.Drawing.Color.Purple;
this.linkLabelCancelAV.LinkColor = System.Drawing.Color.DarkRed;
this.linkLabelCancelAV.Location = new System.Drawing.Point(75, 332);
this.linkLabelCancelAV.Name = "linkLabelCancelAV";
this.linkLabelCancelAV.Size = new System.Drawing.Size(37, 15);
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, 224);
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.AutoSize = true;
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.Name = "MyAV";
this.Size = new System.Drawing.Size(296, 412);
((System.ComponentModel.ISupportInitialize)(this.trackBarIn)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.trackBarOut)).EndInit();
this.panel1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.picRemote)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.picRemoteBack)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit();
this.panelSelfAV.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.picLocal)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
public void SetParameter(System.Net.IPAddress ip, int port, string sendID)
{
this.serverIp =ip;
this.serverPort=port;
this.sendId =sendID ;
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 (this.picLocal ,this.picRemote );
this.av.IniChanel();
}
public AV AV
{
get{return this.av;}
}
private bool IsAV=false;//表示当前是否正在视频中
private void ReadyConnect()//准备连接,并告诉对方本地IP与端口,让其联接
{
if(!IsAV)
{
Initialize();
byte[] msg = IMLibrary.TextEncoder.textToBytes(this.sendId );
byte[] buf = new byte[msg.Length + 2];
buf[0] = 255;//合法用户标识
buf[1] = 20;//消息类型
Buffer.BlockCopy(msg, 0, buf, 2, msg.Length);
this.av.ReadyStrat(buf, 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);//触发接收事件
Initialize();//初始化视频设备
this.av.IniAudio();//初始化音频设备
this.av.IniVideo();//初始化视频设备
byte[] msg=IMLibrary.TextEncoder.textToBytes(this.sendId );
byte[] buf = new byte[msg.Length + 2];
buf[0] = 255;//合法用户标识
buf[1] = 21;//消息类型
Buffer.BlockCopy(msg, 0, buf, 2, msg.Length);
this.AV.BeginAV( buf ,this.serverIp,this.serverPort);//告诉对方可以开始视频
}
long i;
private void picRemote_Paint(object sender, PaintEventArgs e)
{
i++;
this.label2.Text = i.ToString();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -