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

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