123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- using fis.media.Library.Media.Device;
- using fis.media.ThirdPartLibrary.Tencent;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace fis.media.Managers
- {
- public class DeviceManager
- {
- private TRTCDeviceApi _deviceAPI;
- private static DeviceManager _instance;
- private CameraDevice _currrentCamera;
- private MicDevice _currentMic;
- private SpeakerDevice _currentSpeaker;
- public static DeviceManager Instance => _instance ?? (_instance = new DeviceManager());
- private DeviceManager()
- {
- _deviceAPI = TRTCDeviceApi.Instance;
- Cameras = _deviceAPI.GetCameraDeviceList();
- Speakers = _deviceAPI.GetSpeakerDeviceList();
- Microphones=_deviceAPI.GetMicDeviceList();
- }
- public event EventHandler<VolumeValueArgs> MicValueChanged;
-
- /// <summary>
- /// 相机信息列表
- /// </summary>
- public List<CameraDevice> Cameras { get; }
- /// <summary>
- /// 麦克风信息列表
- /// </summary>
- public List<MicDevice> Microphones { get; }
- /// <summary>
- /// 扬声器信息列表
- /// </summary>
- public List<SpeakerDevice> Speakers { get; }
-
- /// <summary>
- /// 当前相机
- /// </summary>
- public CameraDevice CurrentCamera {
- get {
- return _currrentCamera;
- }
- set {
- if (_currrentCamera == null || value.DeviceId != _currrentCamera.DeviceId)
- {
- _currrentCamera = value;
- _deviceAPI.SetCurrentCameraDevice(_currrentCamera.DeviceId);
- }
- }
- }
- /// <summary>
- /// 当前麦克风ID
- /// </summary>
- public MicDevice CurrentMic
- {
- get {
- return _currentMic;
- }
- set
- {
- if (_currentMic == null|| _currentMic.DeviceId != value.DeviceId)
- {
- _currentMic = value;
- _deviceAPI.SetCurrentMicDevice(_currentMic.DeviceId);
- }
-
- }
- }
- /// <summary>
- /// 扬声器ID
- /// </summary>
- public SpeakerDevice CurrentSpeaker
- {
- get {
- return _currentSpeaker;
- }
- set {
- if (_currentSpeaker == null || _currentSpeaker.DeviceId != value.DeviceId)
- {
- if (_currentSpeaker != null)
- {
- _currentSpeaker.TestVolumChanged -= OnTestValueChanged;
- }
- _currentSpeaker = value;
- _currentSpeaker.TestVolumChanged += OnTestValueChanged;
- _deviceAPI.SetCurrentSpeakerDevice(_currentSpeaker.DeviceId);
- }
- }
- }
- private void OnTestValueChanged(object? sender, VolumeValueArgs volumeValueArgs)
- {
- throw new NotImplementedException();
- }
- /// <summary>
- /// 开始麦克风测试
- /// </summary>
- public void StartMicTest()
- {
- CurrentMic.StartTest();
- }
- /// <summary>
- /// 停止麦克风测试
- /// </summary>
- public void StopMicTest()
- {
- CurrentSpeaker.StopTest();
- }
- /// <summary>
- /// 开始扬声器测试
- /// </summary>
- public void StartSpeakerTest()
- {
- CurrentSpeaker.StartTest();
- }
- /// <summary>
- /// 停止扬声器测试
- /// </summary>
- public void StopSpeakerTest()
- {
- CurrentSpeaker.StopTest();
- }
-
- }
- }
|