DeviceDetector.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. using System;
  2. using Vinno.IUS.Common.Log;
  3. using Vinno.vCloud.Common.FIS;
  4. namespace Vinno.vCloud.FIS.Windows
  5. {
  6. class DeviceDetector : IDeviceDetector
  7. {
  8. private string _currentMicId;
  9. private string _currentSpeakerId;
  10. /// <summary>
  11. /// Raised when mic volume is change.
  12. /// </summary>
  13. public event EventHandler<uint> MicVolumeUpdated;
  14. /// <summary>
  15. /// Raised when speaking volume is change.
  16. /// </summary>
  17. public event EventHandler<uint> SpeakerVolumeUpdated;
  18. public DeviceDetector()
  19. {
  20. TrtcDetector.Instance.MicVolumeUpdated += OnMicVolumeUpdated;
  21. TrtcDetector.Instance.SpeakerVolumeUpdated += OnSpeakerVolumeUpdated;
  22. }
  23. public void StartMicTest(string micId, string speakerId)
  24. {
  25. if (string.IsNullOrEmpty(_currentMicId))
  26. {
  27. _currentMicId = micId;
  28. TrtcDetector.Instance.StartMicTest(micId, speakerId);
  29. }
  30. else
  31. {
  32. Logger.WriteLineError($"Start mic {micId} test error because another mic {_currentMicId} already testing");
  33. }
  34. }
  35. /// <summary>
  36. /// Stop mic test.
  37. /// </summary>
  38. public void StopMicTest()
  39. {
  40. TrtcDetector.Instance.StopMicTest();
  41. _currentMicId = null;
  42. }
  43. /// <summary>
  44. /// Set mic device volume
  45. /// </summary>
  46. /// <param name="micId">The mic device id.</param>
  47. /// <param name="volume">The volume of the mic.</param>
  48. public void SetMicDeviceVolume(string micId, uint volume)
  49. {
  50. TrtcDetector.Instance.SetMicDeviceVolume(micId, volume);
  51. }
  52. /// <summary>
  53. /// Start speaker test.
  54. /// </summary>
  55. /// <param name="speakerId">The speaker id.</param>
  56. /// <param name="audioFilePath">The audio file path.</param>
  57. public void StartSpeakerTest(string speakerId, string audioFilePath)
  58. {
  59. if (string.IsNullOrEmpty(_currentSpeakerId))
  60. {
  61. _currentSpeakerId = speakerId;
  62. TrtcDetector.Instance.StartSpeakerTest(speakerId, audioFilePath);
  63. }
  64. else
  65. {
  66. Logger.WriteLineError($"Start speaker {speakerId} test error because another speaker {_currentMicId} already testing");
  67. }
  68. }
  69. /// <summary>
  70. /// Stop speaker test.
  71. /// </summary>
  72. public void StopSpeakerTest()
  73. {
  74. TrtcDetector.Instance.StopSpeakerTest();
  75. _currentSpeakerId = null;
  76. }
  77. /// <summary>
  78. /// Set speaker volume.
  79. /// </summary>
  80. /// <param name="speakerId">The speaker device id.</param>
  81. /// <param name="volume">The volume of the speaker.</param>
  82. public void SetSpeakerVolume(string speakerId, uint volume)
  83. {
  84. TrtcDetector.Instance.SetSpeakerVolume(speakerId, volume);
  85. }
  86. /// <summary>
  87. /// Set speakder mute.
  88. /// </summary>
  89. /// <param name="speakerId">The speaker id.</param>
  90. /// <param name="isMute">True: mute, False: not mute.</param>
  91. /// <returns></returns>
  92. public void SetSpeakerMute(string speakerId, bool isMute)
  93. {
  94. TrtcDetector.Instance.SetSpeakerMute(speakerId, isMute);
  95. }
  96. /// <summary>
  97. /// Set speakder mute.
  98. /// </summary>
  99. /// <param name="micId">The mic id.</param>
  100. /// <param name="isMute">True: mute, False: not mute.</param>
  101. /// <returns></returns>
  102. public void SetMicMute(string micId, bool isMute)
  103. {
  104. TrtcDetector.Instance.SetMicMute(micId, isMute);
  105. }
  106. /// <summary>
  107. /// Dispose.
  108. /// </summary>
  109. public void Dispose()
  110. {
  111. TrtcDetector.Instance.MicVolumeUpdated -= OnMicVolumeUpdated;
  112. TrtcDetector.Instance.SpeakerVolumeUpdated -= OnSpeakerVolumeUpdated;
  113. }
  114. private void OnSpeakerVolumeUpdated(object sender, uint e)
  115. {
  116. SpeakerVolumeUpdated?.Invoke(this, e);
  117. }
  118. private void OnMicVolumeUpdated(object sender, uint e)
  119. {
  120. MicVolumeUpdated.Invoke(this, e);
  121. }
  122. }
  123. }