123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- using System;
- using Vinno.IUS.Common.Log;
- using Vinno.vCloud.Common.FIS;
- namespace Vinno.vCloud.FIS.Windows
- {
- class DeviceDetector : IDeviceDetector
- {
- private string _currentMicId;
- private string _currentSpeakerId;
- /// <summary>
- /// Raised when mic volume is change.
- /// </summary>
- public event EventHandler<uint> MicVolumeUpdated;
- /// <summary>
- /// Raised when speaking volume is change.
- /// </summary>
- public event EventHandler<uint> SpeakerVolumeUpdated;
- public DeviceDetector()
- {
- TrtcDetector.Instance.MicVolumeUpdated += OnMicVolumeUpdated;
- TrtcDetector.Instance.SpeakerVolumeUpdated += OnSpeakerVolumeUpdated;
- }
- public void StartMicTest(string micId, string speakerId)
- {
- if (string.IsNullOrEmpty(_currentMicId))
- {
- _currentMicId = micId;
- TrtcDetector.Instance.StartMicTest(micId, speakerId);
- }
- else
- {
- Logger.WriteLineError($"Start mic {micId} test error because another mic {_currentMicId} already testing");
- }
- }
- /// <summary>
- /// Stop mic test.
- /// </summary>
- public void StopMicTest()
- {
- TrtcDetector.Instance.StopMicTest();
- _currentMicId = null;
- }
- /// <summary>
- /// Set mic device volume
- /// </summary>
- /// <param name="micId">The mic device id.</param>
- /// <param name="volume">The volume of the mic.</param>
- public void SetMicDeviceVolume(string micId, uint volume)
- {
- TrtcDetector.Instance.SetMicDeviceVolume(micId, volume);
- }
- /// <summary>
- /// Start speaker test.
- /// </summary>
- /// <param name="speakerId">The speaker id.</param>
- /// <param name="audioFilePath">The audio file path.</param>
- public void StartSpeakerTest(string speakerId, string audioFilePath)
- {
- if (string.IsNullOrEmpty(_currentSpeakerId))
- {
- _currentSpeakerId = speakerId;
- TrtcDetector.Instance.StartSpeakerTest(speakerId, audioFilePath);
- }
- else
- {
- Logger.WriteLineError($"Start speaker {speakerId} test error because another speaker {_currentMicId} already testing");
- }
- }
- /// <summary>
- /// Stop speaker test.
- /// </summary>
- public void StopSpeakerTest()
- {
- TrtcDetector.Instance.StopSpeakerTest();
- _currentSpeakerId = null;
- }
- /// <summary>
- /// Set speaker volume.
- /// </summary>
- /// <param name="speakerId">The speaker device id.</param>
- /// <param name="volume">The volume of the speaker.</param>
- public void SetSpeakerVolume(string speakerId, uint volume)
- {
- TrtcDetector.Instance.SetSpeakerVolume(speakerId, volume);
- }
- /// <summary>
- /// Set speakder mute.
- /// </summary>
- /// <param name="speakerId">The speaker id.</param>
- /// <param name="isMute">True: mute, False: not mute.</param>
- /// <returns></returns>
- public void SetSpeakerMute(string speakerId, bool isMute)
- {
- TrtcDetector.Instance.SetSpeakerMute(speakerId, isMute);
- }
- /// <summary>
- /// Set speakder mute.
- /// </summary>
- /// <param name="micId">The mic id.</param>
- /// <param name="isMute">True: mute, False: not mute.</param>
- /// <returns></returns>
- public void SetMicMute(string micId, bool isMute)
- {
- TrtcDetector.Instance.SetMicMute(micId, isMute);
- }
- /// <summary>
- /// Dispose.
- /// </summary>
- public void Dispose()
- {
- TrtcDetector.Instance.MicVolumeUpdated -= OnMicVolumeUpdated;
- TrtcDetector.Instance.SpeakerVolumeUpdated -= OnSpeakerVolumeUpdated;
- }
- private void OnSpeakerVolumeUpdated(object sender, uint e)
- {
- SpeakerVolumeUpdated?.Invoke(this, e);
- }
- private void OnMicVolumeUpdated(object sender, uint e)
- {
- MicVolumeUpdated.Invoke(this, e);
- }
- }
- }
|