DeviceManager.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. using fis.media.Library.Media.Device;
  2. using fis.media.ThirdPartLibrary.Tencent;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace fis.media.Managers
  9. {
  10. public class DeviceManager
  11. {
  12. private TRTCDeviceApi _deviceAPI;
  13. private static DeviceManager _instance;
  14. private CameraDevice _currrentCamera;
  15. private MicDevice _currentMic;
  16. private SpeakerDevice _currentSpeaker;
  17. public static DeviceManager Instance => _instance ?? (_instance = new DeviceManager());
  18. private DeviceManager()
  19. {
  20. _deviceAPI = TRTCDeviceApi.Instance;
  21. Cameras = _deviceAPI.GetCameraDeviceList();
  22. Speakers = _deviceAPI.GetSpeakerDeviceList();
  23. Microphones=_deviceAPI.GetMicDeviceList();
  24. }
  25. public event EventHandler<VolumeValueArgs> MicValueChanged;
  26. /// <summary>
  27. /// 相机信息列表
  28. /// </summary>
  29. public List<CameraDevice> Cameras { get; }
  30. /// <summary>
  31. /// 麦克风信息列表
  32. /// </summary>
  33. public List<MicDevice> Microphones { get; }
  34. /// <summary>
  35. /// 扬声器信息列表
  36. /// </summary>
  37. public List<SpeakerDevice> Speakers { get; }
  38. /// <summary>
  39. /// 当前相机
  40. /// </summary>
  41. public CameraDevice CurrentCamera {
  42. get {
  43. return _currrentCamera;
  44. }
  45. set {
  46. if (_currrentCamera == null || value.DeviceId != _currrentCamera.DeviceId)
  47. {
  48. _currrentCamera = value;
  49. _deviceAPI.SetCurrentCameraDevice(_currrentCamera.DeviceId);
  50. }
  51. }
  52. }
  53. /// <summary>
  54. /// 当前麦克风ID
  55. /// </summary>
  56. public MicDevice CurrentMic
  57. {
  58. get {
  59. return _currentMic;
  60. }
  61. set
  62. {
  63. if (_currentMic == null|| _currentMic.DeviceId != value.DeviceId)
  64. {
  65. _currentMic = value;
  66. _deviceAPI.SetCurrentMicDevice(_currentMic.DeviceId);
  67. }
  68. }
  69. }
  70. /// <summary>
  71. /// 扬声器ID
  72. /// </summary>
  73. public SpeakerDevice CurrentSpeaker
  74. {
  75. get {
  76. return _currentSpeaker;
  77. }
  78. set {
  79. if (_currentSpeaker == null || _currentSpeaker.DeviceId != value.DeviceId)
  80. {
  81. if (_currentSpeaker != null)
  82. {
  83. _currentSpeaker.TestVolumChanged -= OnTestValueChanged;
  84. }
  85. _currentSpeaker = value;
  86. _currentSpeaker.TestVolumChanged += OnTestValueChanged;
  87. _deviceAPI.SetCurrentSpeakerDevice(_currentSpeaker.DeviceId);
  88. }
  89. }
  90. }
  91. private void OnTestValueChanged(object? sender, VolumeValueArgs volumeValueArgs)
  92. {
  93. throw new NotImplementedException();
  94. }
  95. /// <summary>
  96. /// 开始麦克风测试
  97. /// </summary>
  98. public void StartMicTest()
  99. {
  100. CurrentMic.StartTest();
  101. }
  102. /// <summary>
  103. /// 停止麦克风测试
  104. /// </summary>
  105. public void StopMicTest()
  106. {
  107. CurrentSpeaker.StopTest();
  108. }
  109. /// <summary>
  110. /// 开始扬声器测试
  111. /// </summary>
  112. public void StartSpeakerTest()
  113. {
  114. CurrentSpeaker.StartTest();
  115. }
  116. /// <summary>
  117. /// 停止扬声器测试
  118. /// </summary>
  119. public void StopSpeakerTest()
  120. {
  121. CurrentSpeaker.StopTest();
  122. }
  123. }
  124. }