AVForm.cs
上传用户:lqb116
上传日期:2014-04-04
资源大小:2712k
文件大小:17k
源码类别:

P2P编程

开发平台:

C#

  1. using System;
  2. using System.IO;
  3. using System.Xml;
  4. using System.Threading;
  5. using System.Drawing;
  6. using System.Collections;
  7. using System.Windows.Forms;
  8. using gowk.core.managers;
  9. using gowk.core.packets;
  10. using gowk.core.packets.querys;
  11. using gowk.net.Sockets;
  12. using gowk.core;
  13. using gowk.net;
  14. using gowk.controls;
  15. using gowk.multimedia;
  16. namespace gowk.forms
  17. {
  18. /// <summary>
  19. /// AVForm 的摘要说明。
  20. /// </summary>
  21. public class AVForm :gowk.controls.GForm
  22. {
  23. gowk.multimedia.AV av;
  24. Form master;
  25. private gowk.controls.GButton remote;
  26. private gowk.controls.GButton local;
  27. private Image upImage,downImage;
  28. private gowk.controls.GPanel gPanel1;
  29. private gowk.controls.GPanel gPanel2;
  30. private gowk.controls.GButton gButton3;
  31. gowk.multimedia.Mixer mixer;
  32. gowk.multimedia.Mixer.MixerControlDetail indtl,outdtl;
  33. private System.Windows.Forms.ProgressBar involume;
  34. private System.Windows.Forms.ProgressBar outvolume;
  35. gowk.common.SkinConfig skf;
  36. private gowk.controls.GButton btnoutvalume;
  37. private gowk.controls.GButton btninvolume;
  38. private System.Windows.Forms.PictureBox r;
  39. private System.Windows.Forms.PictureBox l;
  40. /// <summary>
  41. /// 必需的设计器变量。
  42. /// </summary>
  43. private System.ComponentModel.Container components = null;
  44. public AVForm()
  45. {
  46. InitializeComponent();
  47. this.InitializeMixing();
  48. gowk.common.SkinConfig.Instance.SkinChanged+=new EventHandler(Instance_SkinChanged);
  49. this.LoadSkin();
  50. this.l.Visible=false;
  51. this.r.Visible=true;
  52. int h=this.remote.Height+this.local.Height+40+r.Height;
  53. if(this.ImageTopLeft!=null)h+=this.ImageTopLeft.Height;
  54. if(this.ImageBottomLeft!=null)h+=this.ImageBottomLeft.Height;
  55. this.Height=h;
  56. }
  57. public AVForm(Form master):this()
  58. {
  59. this.master=master;
  60. this.master.Move+=new EventHandler(master_Move);
  61. this.master.VisibleChanged+=new EventHandler(master_VisibleChanged);
  62. this.master.SizeChanged+=new EventHandler(master_SizeChanged);
  63. }
  64. private void InitializeMixing()
  65. {
  66. mixer=new Mixer(this);
  67. mixer.MixerControlChange+=new EventHandler(mixer_MixerControlChange);
  68. this.outdtl=new gowk.multimedia.Mixer.MixerControlDetail(mixer,gowk.multimedia.Mixer.MIXERLINE_COMPONENTTYPE_DST_SPEAKERS);
  69. this.outvolume.Minimum=this.outdtl.Min;
  70. this.outvolume.Maximum=this.outdtl.Max;
  71. this.outvolume.Value=this.outdtl.Volume;
  72. this.indtl=new gowk.multimedia.Mixer.MixerControlDetail(mixer,gowk.multimedia.Mixer.MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE);
  73. this.involume.Minimum=indtl.Min;
  74. this.involume.Maximum=indtl.Max;
  75. this.involume.Value=this.indtl.Volume;
  76. }
  77. private void SyncVolumn()
  78. {
  79. this.involume.Value=this.indtl.Volume;
  80. this.outvolume.Value=this.outdtl.Volume;
  81. // this.btnoutvalume.BackgroundImage=this.indtl.Mute?skf.GetImage("/gowk_skin/images/avform/speakerdisabled"):skf.GetImage("/gowk_skin/images/avform/speaker");
  82. // this.btninvolume.BackgroundImage=this.outdtl.Mute?skf.GetImage("/gowk_skin/images/avform/microphonedisabled"):skf.GetImage("/gowk_skin/images/avform/microphone");
  83. }
  84. private void mixer_MixerControlChange(object sender, EventArgs e)
  85. {
  86. this.SyncVolumn();
  87. }
  88. private void Instance_SkinChanged(object sender, EventArgs e)
  89. {
  90. this.LoadSkin();
  91. }
  92. public void Initialize()
  93. {
  94. if(av!=null)this.av.Dispose();
  95. this.av=new AV(this.l,this.r);
  96. this.av.IniChanel();
  97. }
  98. public AV AV
  99. {
  100. get{return this.av;}
  101. }
  102. public void Connect(string ip,int port)
  103. {
  104. this.av.IniAudio();
  105. this.av.IniVideo();
  106. this.av.Start(ip,port);
  107. }
  108. public void Stop()
  109. {
  110. if(this.av!=null)this.av.Dispose();
  111. }
  112. private void LoadSkin()
  113. {
  114. skf=gowk.common.SkinConfig.Instance;
  115. this.upImage=skf.GetImage("/gowk_skin/images/avform/up");
  116. this.downImage=skf.GetImage("/gowk_skin/images/avform/down");
  117. this.local.GImage.ActiveImage=this.local.GImage.PressedImage=this.local.GImage.NormalImage=null;
  118. this.remote.GImage.ActiveImage=this.remote.GImage.PressedImage=this.remote.GImage.NormalImage=null;
  119. this.remote.GImage.Image=this.r.Visible?this.upImage:this.downImage;
  120. this.local.GImage.Image=this.l.Visible?this.upImage:this.downImage;
  121. this.ImageTopLeft=skf.GetImage("/gowk_skin/images/form/t1");
  122. this.ImageTopCenter=skf.GetImage("/gowk_skin/images/form/t2");
  123. this.ImageTopRight=skf.GetImage("/gowk_skin/images/form/t3");
  124. this.ImageMiddleLeft=skf.GetImage("/gowk_skin/images/form/m1");
  125. this.ImageMiddleCenter=skf.GetImage("/gowk_skin/images/form/m2");
  126. this.ImageMiddleRight=skf.GetImage("/gowk_skin/images/form/m3");
  127. this.ImageBottomLeft=skf.GetImage("/gowk_skin/images/form/b1");
  128. this.ImageBottomCenter=skf.GetImage("/gowk_skin/images/form/b2");
  129. this.ImageBottomRight=skf.GetImage("/gowk_skin/images/form/b3");
  130. this.btnoutvalume.BackgroundImage=skf.GetImage("/gowk_skin/images/avform/speaker");
  131. this.btninvolume.BackgroundImage=skf.GetImage("/gowk_skin/images/avform/microphone");
  132. // this.btnoutvalume.BackgroundImage=this.indtl.Mute?skf.GetImage("/gowk_skin/images/avform/speakerdisabled"):skf.GetImage("/gowk_skin/images/avform/speaker");
  133. // this.btninvolume.BackgroundImage=this.outdtl.Mute?skf.GetImage("/gowk_skin/images/avform/microphonedisabled"):skf.GetImage("/gowk_skin/images/avform/microphone");
  134. }
  135. protected override void Dispose( bool disposing )
  136. {
  137. if( disposing )
  138. {
  139. mixer.MixerControlChange-=new EventHandler(mixer_MixerControlChange);
  140. gowk.common.SkinConfig.Instance.SkinChanged-=new EventHandler(Instance_SkinChanged);
  141. try
  142. {
  143. this.av.Dispose();
  144. }
  145. catch(System.Exception ex)
  146. {
  147. gowk.utility.Diagnostics.Debug.Write(ex);
  148. }
  149. if(components != null)
  150. {
  151. components.Dispose();
  152. }
  153. }
  154. base.Dispose( disposing );
  155. }
  156. #region Windows 窗体设计器生成的代码
  157. /// <summary>
  158. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  159. /// 此方法的内容。
  160. /// </summary>
  161. private void InitializeComponent()
  162. {
  163. System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(AVForm));
  164. this.remote = new gowk.controls.GButton();
  165. this.local = new gowk.controls.GButton();
  166. this.gPanel1 = new gowk.controls.GPanel();
  167. this.gPanel2 = new gowk.controls.GPanel();
  168. this.gButton3 = new gowk.controls.GButton();
  169. this.outvolume = new System.Windows.Forms.ProgressBar();
  170. this.btnoutvalume = new gowk.controls.GButton();
  171. this.btninvolume = new gowk.controls.GButton();
  172. this.involume = new System.Windows.Forms.ProgressBar();
  173. this.r = new System.Windows.Forms.PictureBox();
  174. this.l = new System.Windows.Forms.PictureBox();
  175. this.gPanel1.SuspendLayout();
  176. this.gPanel2.SuspendLayout();
  177. this.SuspendLayout();
  178. // 
  179. // remote
  180. // 
  181. this.remote.BackColor = System.Drawing.Color.Transparent;
  182. this.remote.Dock = System.Windows.Forms.DockStyle.Top;
  183. this.remote.GBorderStyle = gowk.controls.GBorderStyle.Solid;
  184. this.remote.IsRound = true;
  185. this.remote.Location = new System.Drawing.Point(0, 22);
  186. this.remote.Name = "remote";
  187. this.remote.Size = new System.Drawing.Size(168, 20);
  188. this.remote.TabIndex = 1;
  189. this.remote.Click += new System.EventHandler(this.remote_Click);
  190. // 
  191. // local
  192. // 
  193. this.local.BackColor = System.Drawing.Color.Transparent;
  194. this.local.Dock = System.Windows.Forms.DockStyle.Bottom;
  195. this.local.GBorderStyle = gowk.controls.GBorderStyle.Solid;
  196. this.local.IsRound = true;
  197. this.local.Location = new System.Drawing.Point(0, 332);
  198. this.local.Name = "local";
  199. this.local.Size = new System.Drawing.Size(168, 20);
  200. this.local.TabIndex = 3;
  201. this.local.Click += new System.EventHandler(this.local_Click);
  202. // 
  203. // gPanel1
  204. // 
  205. this.gPanel1.BackColor = System.Drawing.Color.Transparent;
  206. this.gPanel1.Controls.Add(this.gPanel2);
  207. this.gPanel1.Controls.Add(this.l);
  208. this.gPanel1.Controls.Add(this.r);
  209. this.gPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
  210. this.gPanel1.GBorderStyle = gowk.controls.GBorderStyle.Solid;
  211. this.gPanel1.IsRound = true;
  212. this.gPanel1.Location = new System.Drawing.Point(0, 42);
  213. this.gPanel1.Name = "gPanel1";
  214. this.gPanel1.Size = new System.Drawing.Size(168, 290);
  215. this.gPanel1.TabIndex = 5;
  216. // 
  217. // gPanel2
  218. // 
  219. this.gPanel2.Controls.Add(this.gButton3);
  220. this.gPanel2.Controls.Add(this.outvolume);
  221. this.gPanel2.Controls.Add(this.btnoutvalume);
  222. this.gPanel2.Controls.Add(this.btninvolume);
  223. this.gPanel2.Controls.Add(this.involume);
  224. this.gPanel2.Dock = System.Windows.Forms.DockStyle.Fill;
  225. this.gPanel2.GBorderStyle = gowk.controls.GBorderStyle.Solid;
  226. this.gPanel2.IsRound = true;
  227. this.gPanel2.Location = new System.Drawing.Point(0, 124);
  228. this.gPanel2.Name = "gPanel2";
  229. this.gPanel2.Size = new System.Drawing.Size(168, 38);
  230. this.gPanel2.TabIndex = 6;
  231. // 
  232. // gButton3
  233. // 
  234. this.gButton3.Anchor = System.Windows.Forms.AnchorStyles.None;
  235. this.gButton3.GBorderStyle = gowk.controls.GBorderStyle.Solid;
  236. this.gButton3.IsRound = true;
  237. this.gButton3.Location = new System.Drawing.Point(142, 10);
  238. this.gButton3.Name = "gButton3";
  239. this.gButton3.Size = new System.Drawing.Size(16, 16);
  240. this.gButton3.TabIndex = 12;
  241. // 
  242. // outvolume
  243. // 
  244. this.outvolume.Anchor = System.Windows.Forms.AnchorStyles.None;
  245. this.outvolume.Location = new System.Drawing.Point(38, 24);
  246. this.outvolume.Name = "outvolume";
  247. this.outvolume.Size = new System.Drawing.Size(100, 8);
  248. this.outvolume.TabIndex = 11;
  249. this.outvolume.MouseUp += new System.Windows.Forms.MouseEventHandler(this.outvolume_MouseUp);
  250. this.outvolume.MouseMove += new System.Windows.Forms.MouseEventHandler(this.outvolume_MouseMove);
  251. // 
  252. // btnoutvalume
  253. // 
  254. this.btnoutvalume.Anchor = System.Windows.Forms.AnchorStyles.None;
  255. this.btnoutvalume.GBorderStyle = gowk.controls.GBorderStyle.Solid;
  256. this.btnoutvalume.IsRound = true;
  257. this.btnoutvalume.Location = new System.Drawing.Point(14, 20);
  258. this.btnoutvalume.Name = "btnoutvalume";
  259. this.btnoutvalume.Size = new System.Drawing.Size(16, 16);
  260. this.btnoutvalume.TabIndex = 10;
  261. this.btnoutvalume.Click += new System.EventHandler(this.btnoutvalume_Click);
  262. // 
  263. // btninvolume
  264. // 
  265. this.btninvolume.Anchor = System.Windows.Forms.AnchorStyles.None;
  266. this.btninvolume.GBorderStyle = gowk.controls.GBorderStyle.Solid;
  267. this.btninvolume.IsRound = true;
  268. this.btninvolume.Location = new System.Drawing.Point(14, 1);
  269. this.btninvolume.Name = "btninvolume";
  270. this.btninvolume.Size = new System.Drawing.Size(16, 16);
  271. this.btninvolume.TabIndex = 9;
  272. this.btninvolume.Click += new System.EventHandler(this.btninvolume_Click);
  273. // 
  274. // involume
  275. // 
  276. this.involume.Anchor = System.Windows.Forms.AnchorStyles.None;
  277. this.involume.Location = new System.Drawing.Point(38, 5);
  278. this.involume.Name = "involume";
  279. this.involume.Size = new System.Drawing.Size(100, 8);
  280. this.involume.TabIndex = 8;
  281. this.involume.MouseUp += new System.Windows.Forms.MouseEventHandler(this.involume_MouseUp);
  282. this.involume.MouseMove += new System.Windows.Forms.MouseEventHandler(this.involume_MouseMove);
  283. // 
  284. // r
  285. // 
  286. this.r.Dock = System.Windows.Forms.DockStyle.Top;
  287. this.r.Image = ((System.Drawing.Image)(resources.GetObject("r.Image")));
  288. this.r.Location = new System.Drawing.Point(0, 0);
  289. this.r.Name = "r";
  290. this.r.Size = new System.Drawing.Size(168, 124);
  291. this.r.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
  292. this.r.TabIndex = 7;
  293. this.r.TabStop = false;
  294. // 
  295. // l
  296. // 
  297. this.l.Dock = System.Windows.Forms.DockStyle.Bottom;
  298. this.l.Image = ((System.Drawing.Image)(resources.GetObject("l.Image")));
  299. this.l.Location = new System.Drawing.Point(0, 162);
  300. this.l.Name = "l";
  301. this.l.Size = new System.Drawing.Size(168, 128);
  302. this.l.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
  303. this.l.TabIndex = 8;
  304. this.l.TabStop = false;
  305. // 
  306. // AVForm
  307. // 
  308. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  309. this.BackColor = System.Drawing.Color.Gray;
  310. this.ClientSize = new System.Drawing.Size(168, 352);
  311. this.Controls.Add(this.gPanel1);
  312. this.Controls.Add(this.local);
  313. this.Controls.Add(this.remote);
  314. this.DockPadding.Top = 22;
  315. this.Name = "AVForm";
  316. this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
  317. this.Text = "AVForm";
  318. this.TransparencyKey = System.Drawing.Color.FromArgb(((System.Byte)(128)), ((System.Byte)(128)), ((System.Byte)(128)));
  319. this.gPanel1.ResumeLayout(false);
  320. this.gPanel2.ResumeLayout(false);
  321. this.ResumeLayout(false);
  322. }
  323. #endregion
  324. private void SetHeight()
  325. {
  326. int h=this.remote.Height+this.local.Height+40;
  327. if(this.ImageTopLeft!=null)h+=this.ImageTopLeft.Height;
  328. if(this.ImageBottomLeft!=null)h+=this.ImageBottomLeft.Height;
  329. if(this.l.Visible)h+=l.Height;
  330. if(this.r.Visible)h+=r.Height;
  331. this.Height=h;
  332. }
  333. private void remote_Click(object sender, System.EventArgs e)
  334. {
  335. this.remote.GImage.ActiveImage=this.remote.GImage.PressedImage=this.remote.GImage.NormalImage=null;
  336. if(this.r.Visible)
  337. {
  338. this.r.Hide();
  339. this.remote.GImage.Image=this.downImage;
  340. }
  341. else
  342. {
  343. this.r.Show();
  344. this.remote.GImage.Image=this.upImage;
  345. }
  346. SetHeight();
  347. }
  348. private void local_Click(object sender, System.EventArgs e)
  349. {
  350. this.local.GImage.ActiveImage=this.local.GImage.PressedImage=this.local.GImage.NormalImage=null;
  351. if(this.l.Visible)
  352. {
  353. this.l.Hide();
  354. this.local.GImage.Image=this.downImage;
  355. }
  356. else
  357. {
  358. this.l.Show();
  359. this.local.GImage.Image=this.upImage;
  360. }
  361. SetHeight();
  362. }
  363. private void master_Move(object sender, EventArgs e)
  364. {
  365. this.XX();
  366. }
  367. private void master_VisibleChanged(object sender, EventArgs e)
  368. {
  369. this.Visible=this.master.Visible;
  370. }
  371. private void master_SizeChanged(object sender, EventArgs e)
  372. {
  373. this.XX();
  374. }
  375. protected override void OnLocationChanged(EventArgs e)
  376. {
  377. base.OnLocationChanged (e);
  378. this.XX();
  379. }
  380. private bool contains(int value,int min,int max)
  381. {
  382. return value<max && value>min;
  383. }
  384. private void XX()
  385. {
  386. if(!this.Visible && !this.master.Visible)return;
  387. if(this.WindowState==FormWindowState.Minimized ||this.master.WindowState==FormWindowState.Minimized)return;
  388. Rectangle mb=this.master.Bounds;
  389. Rectangle lb=this.Bounds;
  390. int x=lb.X;
  391. int y=lb.Y;
  392. if(lb.Bottom<mb.Top)
  393. {
  394. y=mb.Top-lb.Height;
  395. }
  396. else if(lb.Top>mb.Bottom)
  397. {
  398. y=mb.Bottom;
  399. }
  400. if(lb.Right<mb.Left)
  401. {
  402. x=mb.Left-lb.Width;
  403. }
  404. else if(lb.Left>mb.Right)
  405. {
  406. x=mb.Right;
  407. }
  408. this.Location=new Point(x,y);
  409. /* Rectangle track=this.master.Bounds;
  410. Rectangle lb=this.Bounds;
  411. track.Inflate(lb.Width,lb.Height);
  412. track.Width-=lb.Width;
  413. track.Height-=lb.Height;
  414. // track.Offset(-5,-5);
  415. int x=lb.X;
  416. int y=lb.Y;
  417. bool xc=this.contains(x,track.Left,track.Right);
  418. bool yc=this.contains(y,track.Top,track.Bottom);
  419. if(xc && !yc)
  420. {
  421. y=track.Top-x>x-track.Bottom?track.Bottom:track.Top;
  422. }
  423. else if(yc && !yc)
  424. {
  425. x=x-track.Left>track.Right-x?track.Right:track.Left;
  426. }
  427. else
  428. x=x<track.Left?track.Left:track.Right;
  429. y=y<track.Top?track.Top:track.Bottom;
  430. }
  431. this.Location=new Point(x,y);*/
  432. }
  433. private void outvolume_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
  434. {
  435. if(e.X<0||e.X>this.outvolume.Width)return;
  436. int v=(int)(e.X*this.outvolume.Maximum/this.outvolume.Width);
  437. this.outdtl.Volume=v;
  438. this.outvolume.Value=this.outdtl.Volume;
  439. }
  440. private void involume_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
  441. {
  442. if(e.X<0||e.X>this.involume.Width)return;
  443. int v=(int)(e.X*this.involume.Maximum/this.involume.Width);
  444. this.indtl.Volume=v;
  445. this.involume.Value=this.indtl.Volume;
  446. }
  447. private void involume_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
  448. {
  449. if(this.involume.Capture)involume_MouseUp(sender,e);
  450. }
  451. private void outvolume_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
  452. {
  453. if(this.outvolume.Capture)outvolume_MouseUp(sender,e);
  454. }
  455. private void btnoutvalume_Click(object sender, System.EventArgs e)
  456. {
  457. // this.outdtl.Mute=!this.outdtl.Mute;
  458. }
  459. private void btninvolume_Click(object sender, System.EventArgs e)
  460. {
  461. // this.indtl.Mute=!this.indtl.Mute;
  462. }
  463. }
  464. }