星火微课系统客户端
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  1. using Common.system;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Threading;
  6. using System.Windows;
  7. using System.Windows.Input;
  8. using System.Windows.Media.Imaging;
  9. using System.Windows.Threading;
  10. namespace XHWK.WKTool
  11. {
  12. /// <summary>
  13. /// DeviceWindow.xaml 的交互逻辑
  14. /// </summary>
  15. public partial class DeviceWindow : Window
  16. {
  17. public DeviceWindow()
  18. {
  19. InitializeComponent();
  20. }
  21. /// <summary>
  22. /// 初始化
  23. /// </summary>
  24. public void Initialize()
  25. {
  26. TxbCamera.Text = "";
  27. TxbSpeaker.Text = "";
  28. TxbMicrophone.Text = "";
  29. BtnDetection.Content = "开始检测";
  30. HidePage();
  31. GridDetection.Visibility = Visibility.Visible;
  32. }
  33. /// <summary>
  34. /// 窗体移动
  35. /// </summary>
  36. /// <param name="sender"></param>
  37. /// <param name="e"></param>
  38. private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  39. {
  40. DragMove();
  41. }
  42. /// <summary>
  43. /// 关闭当前页
  44. /// </summary>
  45. /// <param name="sender"></param>
  46. /// <param name="e"></param>
  47. private void BtnDown_Click(object sender, RoutedEventArgs e)
  48. {
  49. imgPlayer.Visibility = Visibility.Hidden;
  50. try
  51. {
  52. CameraHelper.CloseDevice();
  53. }
  54. catch (Exception)
  55. {
  56. }
  57. Hide();
  58. }
  59. #region 设备检测
  60. /// <summary>
  61. /// 开始检测
  62. /// </summary>
  63. /// <param name="sender"></param>
  64. /// <param name="e"></param>
  65. private void BtnDetection_Click(object sender, RoutedEventArgs e)
  66. {
  67. string AudioPath = FileToolsCommon.GetFileAbsolutePath("/temp/audio/");
  68. FileToolsCommon.CreateDirectory(AudioPath);
  69. string audioSpeakerPath = AudioPath + "adoS" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".m";//FileToolsCommon.GetFileAbsolutePath("adoS.m");
  70. string audioMicrophonePath = AudioPath + "adoM" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".m";//FileToolsCommon.GetFileAbsolutePath("adoM.m");
  71. string PhotoPath = AudioPath + "Photo" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".jpg";
  72. TxbCamera.Text = "检测中...";
  73. TxbSpeaker.Text = "检测中...";
  74. TxbMicrophone.Text = "检测中...";
  75. BtnDetection.Content = "正在检测";
  76. BtnDetection.IsEnabled = false;
  77. try
  78. {
  79. FileToolsCommon.DeleteFile(audioSpeakerPath);
  80. FileToolsCommon.DeleteFile(audioMicrophonePath);
  81. FileToolsCommon.DeleteFile(PhotoPath);
  82. }
  83. catch (Exception)
  84. {
  85. }
  86. new Thread(new ThreadStart(new Action(() =>
  87. {
  88. #region 检测摄像头
  89. try
  90. {
  91. //new Thread(new ThreadStart(new Action(() =>
  92. //{
  93. //Dispatcher.Invoke(() =>
  94. //{
  95. //});
  96. //}))).Start();
  97. Dispatcher.Invoke(() =>
  98. {
  99. CameraHelper.UpdateCameraDevices();
  100. });
  101. Thread.Sleep(500);
  102. if (CameraHelper.CameraDevices != null && CameraHelper.CameraDevices.Count > 0)
  103. {
  104. Dispatcher.Invoke(() =>
  105. {
  106. int CameraIndex = 0;
  107. for (int i = 0; i < CameraHelper.CameraDevices.Count; i++)
  108. {
  109. if (CameraHelper.CameraDevices[i].Name == "screen-capture-recorder")
  110. {
  111. continue;
  112. }
  113. if (CameraHelper.CameraDevices[i].MonikerString == APP.CameraName)
  114. {
  115. CameraIndex = i;
  116. }
  117. }
  118. CameraHelper.SetCameraDevice(CameraIndex);
  119. });
  120. Thread.Sleep(2000);
  121. //while()
  122. Dispatcher.Invoke(() =>
  123. {
  124. long time = Timestamp();
  125. string path = CameraHelper.CaptureImage(PhotoPath, time.ToString());
  126. if (string.IsNullOrWhiteSpace(path))
  127. {
  128. TxbCamera.Text = "不可用";
  129. }
  130. else
  131. {
  132. TxbCamera.Text = "正常";
  133. }
  134. CameraHelper.CloseDevice();
  135. });
  136. }
  137. else
  138. {
  139. Dispatcher.Invoke(() =>
  140. {
  141. TxbCamera.Text = "无设备";
  142. });
  143. }
  144. }
  145. catch (Exception)
  146. {
  147. Dispatcher.Invoke(() =>
  148. {
  149. TxbCamera.Text = "不可用";
  150. });
  151. }
  152. #endregion
  153. #region 检测扬声器
  154. if (APP.FFmpeg.StartRecordSpeakerAudio(audioSpeakerPath))
  155. {
  156. Dispatcher.Invoke(() =>
  157. {
  158. TxbSpeaker.Text = "正常";
  159. });
  160. }
  161. else
  162. {
  163. //无法录制扬声器音频
  164. Dispatcher.Invoke(() =>
  165. {
  166. TxbSpeaker.Text = "不可用";
  167. });
  168. }
  169. APP.FFmpeg.StopRecordAudio(2);
  170. #endregion
  171. Thread.Sleep(300);
  172. #region 检测麦克风
  173. if (APP.FFmpeg.StartRecordAudio(audioMicrophonePath, APP.MicrophoneName))
  174. {
  175. Dispatcher.Invoke(() =>
  176. {
  177. TxbMicrophone.Text = "正常";
  178. });
  179. }
  180. else
  181. {
  182. //无法录制麦克风
  183. Dispatcher.Invoke(() =>
  184. {
  185. TxbMicrophone.Text = "不可用";
  186. });
  187. }
  188. APP.FFmpeg.StopRecordAudio(1);
  189. #endregion
  190. Dispatcher.Invoke(() =>
  191. {
  192. BtnDetection.Content = "再次检测";
  193. BtnDetection.IsEnabled = true;
  194. });
  195. }))).Start();
  196. }
  197. /// <summary>
  198. /// 返回一个时间戳到毫秒
  199. /// </summary>
  200. /// <returns></returns>
  201. public static long Timestamp()
  202. {
  203. TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  204. long timestr = Convert.ToInt64(ts.TotalMilliseconds);
  205. return timestr;
  206. }
  207. #endregion
  208. #region 摄像头
  209. /// <summary>
  210. /// 设置摄像头
  211. /// </summary>
  212. /// <param name="sender"></param>
  213. /// <param name="e"></param>
  214. private void BtnCameraSave_Click(object sender, RoutedEventArgs e)
  215. {
  216. try
  217. {
  218. for (int i = 0; i < CameraHelper.CameraDevices.Count; i++)
  219. {
  220. if (CameraHelper.CameraDevices[i].Name == "screen-capture-recorder")
  221. {
  222. continue;
  223. }
  224. if (CameraHelper.CameraDevices[i].Name == CmbCameraList.Text)
  225. {
  226. APP.CameraName = CameraHelper.CameraDevices[i].Name;
  227. }
  228. }
  229. if (times != null && times.Enabled == true)
  230. {
  231. times.Enabled = false;
  232. }
  233. imgPlayer.Visibility = Visibility.Hidden;
  234. try
  235. {
  236. CameraHelper.CloseDevice();
  237. }
  238. catch (Exception)
  239. {
  240. }
  241. I = 9999;
  242. MessageWindow.Show("设置成功!");
  243. }
  244. catch (Exception ex)
  245. {
  246. APP.CameraName = "";
  247. MessageWindow.Show("当前无法设置摄像头!");
  248. LogHelper.WriteErrLog("【摄像头检测】(DeviceWindow)当前无法设置摄像头:" + ex.Message, ex);
  249. }
  250. //APP.CameraListIndex = CmbCameraList.SelectedIndex;
  251. }
  252. /// <summary>
  253. /// 检测
  254. /// </summary>
  255. /// <param name="sender"></param>
  256. /// <param name="e"></param>
  257. private void BtnCameraStat_Click(object sender, RoutedEventArgs e)
  258. {
  259. try
  260. {
  261. imgPlayer.Visibility = Visibility.Visible;
  262. CameraHelper.UpdateCameraDevices();
  263. if (CameraHelper.CameraDevices.Count > 0)
  264. {
  265. int CameraIndex = 0;
  266. for (int i = 0; i < CameraHelper.CameraDevices.Count; i++)
  267. {
  268. if (CameraHelper.CameraDevices[i].Name == "screen-capture-recorder")
  269. {
  270. continue;
  271. }
  272. if (CameraHelper.CameraDevices[i].MonikerString == APP.CameraName)
  273. {
  274. CameraIndex = i;
  275. }
  276. }
  277. CameraHelper.SetCameraDevice(CameraIndex);
  278. string imgPath = FileToolsCommon.GetFileAbsolutePath("Temp/imgplayertest");
  279. FileToolsCommon.CreateDirectory(imgPath);
  280. times = new System.Timers.Timer(200)//初始值为300
  281. {
  282. AutoReset = true//设置是否执行System.Timers.Timer.Elapsed事件
  283. };//设置执行一次(false)还是一直执行(true)
  284. times.Elapsed += new System.Timers.ElapsedEventHandler(Times_Elapsed);
  285. times.Enabled = true; //启动计时器
  286. }
  287. }
  288. catch (Exception ex)
  289. {
  290. LogHelper.WriteErrLog("【摄像头检测】(DeviceWindow)摄像头不可用:" + ex.Message, ex);
  291. }
  292. }
  293. /// <summary>
  294. /// 停止
  295. /// </summary>
  296. /// <param name="sender"></param>
  297. /// <param name="e"></param>
  298. private void BtnCameraStop_Click(object sender, RoutedEventArgs e)
  299. {
  300. times.Enabled = false;
  301. imgPlayer.Visibility = Visibility.Hidden;
  302. try
  303. {
  304. CameraHelper.CloseDevice();
  305. }
  306. catch (Exception ex)
  307. {
  308. LogHelper.WriteErrLog("【摄像头检测】(DeviceWindow)摄像头不可用:" + ex.Message, ex);
  309. }
  310. I = 9999;
  311. }
  312. #region 检测摄像头
  313. private System.Timers.Timer times;
  314. private int I = 9999;
  315. private void Times_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  316. {
  317. try
  318. {
  319. Dispatcher.Invoke(() =>
  320. {
  321. if (I > 10010)
  322. {
  323. long time = Timestamp();
  324. string imgPath = FileToolsCommon.GetFileAbsolutePath("Temp/imgplayertest");
  325. //string FilePathName = ImgPath + RsImgName.Count + ".png";
  326. string path = CameraHelper.CaptureImage(imgPath, time.ToString());
  327. if (!string.IsNullOrWhiteSpace(path))
  328. {
  329. imgPlayer.Source = new BitmapImage(new Uri(path));
  330. }
  331. }
  332. I++;
  333. });
  334. }
  335. catch (Exception ex)
  336. {
  337. LogHelper.WriteErrLog("【摄像】(Times_Elapsed)生成图片错误:" + ex.Message, ex);
  338. }
  339. }
  340. #endregion
  341. #endregion
  342. #region 扬声器
  343. /// <summary>
  344. /// 检测扬声器
  345. /// </summary>
  346. /// <param name="sender"></param>
  347. /// <param name="e"></param>
  348. private void BtnSpeakerDetection_Click(object sender, RoutedEventArgs e)
  349. {
  350. string AudioPath = FileToolsCommon.GetFileAbsolutePath("/temp/audio/");
  351. FileToolsCommon.CreateDirectory(AudioPath);
  352. string audioSpeakerPath = AudioPath + "adoS" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".m";
  353. TbxSpeakerDetection.Text = "检测中...";
  354. BtnSpeakerDetection.Content = "正在检测";
  355. BtnSpeakerDetection.IsEnabled = false;
  356. new Thread(new ThreadStart(new Action(() =>
  357. {
  358. Dispatcher.Invoke(() =>
  359. {
  360. MediaAudio.Play();
  361. ImgAcousticWave.Visibility = Visibility.Visible;
  362. });
  363. Thread.Sleep(4000);
  364. #region 检测扬声器
  365. if (APP.FFmpeg.StartRecordSpeakerAudio(audioSpeakerPath))
  366. {
  367. Dispatcher.Invoke(() =>
  368. {
  369. TbxSpeakerDetection.Text = "正常";
  370. });
  371. }
  372. else
  373. {
  374. //无法录制扬声器音频
  375. Dispatcher.Invoke(() =>
  376. {
  377. TbxSpeakerDetection.Text = "不可用";
  378. });
  379. }
  380. APP.FFmpeg.StopRecordAudio(2);
  381. #endregion
  382. Dispatcher.Invoke(() =>
  383. {
  384. ImgAcousticWave.Visibility = Visibility.Hidden;
  385. BtnSpeakerDetection.Content = "再次检测";
  386. BtnSpeakerDetection.IsEnabled = true;
  387. });
  388. }))).Start();
  389. }
  390. #region 音频播放
  391. ///// <summary>
  392. ///// 计时器
  393. ///// </summary>
  394. //DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer(); // 定义一个DT
  395. /// <summary>
  396. /// 音频播放 同步进度条和视频进度
  397. /// </summary>
  398. /// <param name="sender"></param>
  399. /// <param name="e"></param>
  400. private void MediaAudio_MediaOpened(object sender, RoutedEventArgs e)
  401. {
  402. //timelineSlider.Maximum = MediaAudio.NaturalDuration.TimeSpan.TotalMilliseconds; //设置slider最大值
  403. //int sec = (int)MediaAudio.NaturalDuration.TimeSpan.TotalSeconds;
  404. //dispatcherTimer.Start(); //DT启动
  405. }
  406. /// <summary>
  407. /// slider滑动值随播放内容位置变化
  408. /// </summary>
  409. /// <param name="sender"></param>
  410. /// <param name="e"></param>
  411. private void dispatcherTimer_Tick(object sender, EventArgs e)
  412. {
  413. //timelineSlider.Value = MediaAudio.Position.TotalMilliseconds; //slider滑动值随播放内容位置变化
  414. }
  415. private void MediaAudio_MediaEnded(object sender, RoutedEventArgs e)
  416. {
  417. //dispatcherTimer.Stop();
  418. //timelineSlider.Value = 0;
  419. MediaAudio.Stop();
  420. MediaAudio.Position = TimeSpan.Zero;
  421. }
  422. #endregion
  423. #endregion
  424. #region 麦克风
  425. /// <summary>
  426. /// 设置麦克风
  427. /// </summary>
  428. /// <param name="sender"></param>
  429. /// <param name="e"></param>
  430. private void BtnMicrophoneSave_Click(object sender, RoutedEventArgs e)
  431. {
  432. //CmbMicrophoneList.SelectedValue.ToString();
  433. APP.MicrophoneName = CmbMicrophoneList.Text;
  434. }
  435. /// <summary>
  436. /// 加载麦克风列表
  437. /// </summary>
  438. void lodingMicrophoneList()
  439. {
  440. //string name = APP.FFmpeg.GetMicrophoneName();
  441. //List<string> MicrophoneList = APP.FFmpeg.GetMicrophoneNameList();
  442. }
  443. /// <summary>
  444. /// 检测麦克风
  445. /// </summary>
  446. /// <param name="sender"></param>
  447. /// <param name="e"></param>
  448. private void BtnMicrophoneDetection_Click(object sender, RoutedEventArgs e)
  449. {
  450. BtnMicrophoneDetectionPlay.Visibility = Visibility.Hidden;
  451. ImgMicAcousticWave.Visibility = Visibility.Hidden;
  452. //GridMicImg.Visibility = Visibility.Hidden;
  453. string AudioPath = FileToolsCommon.GetFileAbsolutePath("/temp/audio/");
  454. FileToolsCommon.CreateDirectory(AudioPath);
  455. string audioMicrophonePath = AudioPath + "adoM" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".mp3";
  456. TbxMicrophoneDetection.Text = "录制中...";
  457. BtnMicrophoneDetection.Content = "正在录制";
  458. BtnMicrophoneDetection.IsEnabled = false;
  459. new Thread(new ThreadStart(new Action(() =>
  460. {
  461. #region 检测麦克风
  462. bool Record = APP.FFmpeg.StartRecordAudio(audioMicrophonePath, APP.MicrophoneName, false);
  463. for (int i = 5; i > 0; i--)
  464. {
  465. Dispatcher.Invoke(() =>
  466. {
  467. TbxMicrophoneDetection.Text = "录制中..." + i + "s";
  468. });
  469. Thread.Sleep(1000);
  470. }
  471. if (Record)
  472. {
  473. Dispatcher.Invoke(() =>
  474. {
  475. TbxMicrophoneDetection.Text = "录制成功";
  476. BtnMicrophoneDetectionPlay.Visibility = Visibility.Visible;
  477. //GridMicImg.Visibility = Visibility.Visible;
  478. MediaAudioMicPlay.Source = new Uri(audioMicrophonePath);
  479. });
  480. }
  481. else
  482. {
  483. //无法录制麦克风
  484. Dispatcher.Invoke(() =>
  485. {
  486. TbxMicrophoneDetection.Text = "不可用";
  487. BtnMicrophoneDetectionPlay.Visibility = Visibility.Hidden;
  488. //GridMicImg.Visibility = Visibility.Hidden;
  489. });
  490. }
  491. APP.FFmpeg.StopRecordAudio(1);
  492. #endregion
  493. Dispatcher.Invoke(() =>
  494. {
  495. BtnMicrophoneDetection.Content = "重新录制";
  496. BtnMicrophoneDetection.IsEnabled = true;
  497. });
  498. }))).Start();
  499. }
  500. /// <summary>
  501. /// 播放录音
  502. /// </summary>
  503. /// <param name="sender"></param>
  504. /// <param name="e"></param>
  505. private void BtnMicrophoneDetectionPlay_Click(object sender, RoutedEventArgs e)
  506. {
  507. BtnMicrophoneDetectionPlay.Content = "播放中";
  508. BtnMicrophoneDetectionPlay.IsEnabled = false;
  509. ImgMicAcousticWave.Visibility = Visibility.Visible;
  510. MediaAudioMicPlay.Play();
  511. }
  512. /// <summary>
  513. /// 播放结束
  514. /// </summary>
  515. /// <param name="sender"></param>
  516. /// <param name="e"></param>
  517. private void MediaAudioMicPlay_MediaEnded(object sender, RoutedEventArgs e)
  518. {
  519. MediaAudioMicPlay.Stop();
  520. MediaAudioMicPlay.Position = TimeSpan.Zero;
  521. BtnMicrophoneDetectionPlay.Content = "播放";
  522. BtnMicrophoneDetectionPlay.IsEnabled = true;
  523. ImgMicAcousticWave.Visibility = Visibility.Hidden;
  524. }
  525. #endregion
  526. #region 页面切换
  527. /// <summary>
  528. /// 摄像头
  529. /// </summary>
  530. /// <param name="sender"></param>
  531. /// <param name="e"></param>
  532. private void BtnCamera_Click(object sender, RoutedEventArgs e)
  533. {
  534. HidePage();
  535. GridCamera.Visibility = Visibility.Visible;
  536. DataTable data = new DataTable();
  537. CameraHelper.UpdateCameraDevices();
  538. if (CameraHelper.CameraDevices.Count > 0)
  539. {
  540. data.Columns.Add("Value");
  541. data.Columns.Add("Key");
  542. for (int i = 0; i < CameraHelper.CameraDevices.Count; i++)
  543. {
  544. if (CameraHelper.CameraDevices[i].Name == "screen-capture-recorder")
  545. {
  546. continue;
  547. }
  548. //创建一行
  549. DataRow row = data.NewRow();
  550. //将此行添加到table中
  551. data.Rows.Add(row);
  552. data.Rows[i]["Value"] = CameraHelper.CameraDevices[i].Name;
  553. data.Rows[i]["Key"] = i.ToString();
  554. }
  555. CmbCameraList.ItemsSource = data.DefaultView;
  556. int CameraIndex = 0;
  557. for (int i = 0; i < CameraHelper.CameraDevices.Count; i++)
  558. {
  559. if (CameraHelper.CameraDevices[i].Name == "screen-capture-recorder")
  560. {
  561. continue;
  562. }
  563. if (CameraHelper.CameraDevices[i].MonikerString == APP.CameraName)
  564. {
  565. CameraIndex = i;
  566. }
  567. }
  568. CmbCameraList.SelectedIndex = CameraIndex;
  569. }
  570. }
  571. /// <summary>
  572. /// 扬声器
  573. /// </summary>
  574. /// <param name="sender"></param>
  575. /// <param name="e"></param>
  576. private void BtnSpeaker_Click(object sender, RoutedEventArgs e)
  577. {
  578. HidePage();
  579. GridSpeaker.Visibility = Visibility.Visible;
  580. MediaAudio.Source = new Uri(FileToolsCommon.GetFileAbsolutePath("/Resources/AudioFrequency.mp3"));
  581. //dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick); //超过计时间隔时发生
  582. //dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 500); //DT间隔
  583. }
  584. /// <summary>
  585. /// 麦克风
  586. /// </summary>
  587. /// <param name="sender"></param>
  588. /// <param name="e"></param>
  589. private void BtnMicrophone_Click(object sender, RoutedEventArgs e)
  590. {
  591. HidePage();
  592. GridMicrophone.Visibility = Visibility.Visible;
  593. BtnMicrophoneDetectionPlay.Visibility = Visibility.Hidden;
  594. ImgMicAcousticWave.Visibility = Visibility.Hidden;
  595. string AudioPath = FileToolsCommon.GetFileAbsolutePath("/temp/audio/");
  596. FileToolsCommon.DeleteDirectory(AudioPath);
  597. DataTable data = new DataTable();
  598. List<string> MicrophoneList = APP.FFmpeg.GetMicrophoneNameList();
  599. if (MicrophoneList.Count > 0)
  600. {
  601. data.Columns.Add("Value");
  602. data.Columns.Add("Key");
  603. for (int i = 0; i < MicrophoneList.Count; i++)
  604. {
  605. //创建一行
  606. DataRow row = data.NewRow();
  607. //将此行添加到table中
  608. data.Rows.Add(row);
  609. data.Rows[i]["Value"] = MicrophoneList[i];
  610. data.Rows[i]["Key"] = i.ToString();
  611. }
  612. CmbMicrophoneList.ItemsSource = data.DefaultView;
  613. int CameraIndex = 0;
  614. if (MicrophoneList.Exists(x => x == APP.MicrophoneName))
  615. {
  616. CameraIndex = MicrophoneList.FindIndex(x => x == APP.MicrophoneName);
  617. }
  618. CmbMicrophoneList.SelectedIndex = CameraIndex;
  619. }
  620. }
  621. /// <summary>
  622. /// 检测页
  623. /// </summary>
  624. /// <param name="sender"></param>
  625. /// <param name="e"></param>
  626. private void BtnDetectionPage_Click(object sender, RoutedEventArgs e)
  627. {
  628. HidePage();
  629. GridDetection.Visibility = Visibility.Visible;
  630. }
  631. /// <summary>
  632. /// 隐藏页
  633. /// </summary>
  634. void HidePage()
  635. {
  636. GridDetection.Visibility = Visibility.Collapsed;
  637. GridCamera.Visibility = Visibility.Collapsed;
  638. GridSpeaker.Visibility = Visibility.Collapsed;
  639. GridMicrophone.Visibility = Visibility.Collapsed;
  640. try
  641. {
  642. CameraHelper.CloseDevice();
  643. }
  644. catch (Exception)
  645. {
  646. }
  647. }
  648. #endregion
  649. }
  650. }