private void OnAudioConfigChanged(bool deviceWasChanged) { if (this.Logger.IsInfoEnabled) { this.Logger.LogInfo("OnAudioConfigChanged deviceWasChange={0}", deviceWasChanged); } if (deviceWasChanged && this.IsRecording) { this.RequiresRestart = true; PhotonMicrophoneEnumerator.Refresh(); this.RestartRecording(); } }
private void HandleDeviceChange() { PhotonMicrophoneEnumerator.Refresh(); if (this.IsRecording && this.SourceType == InputSourceType.Microphone) { if (this.MicrophoneType == MicType.Photon) { this.RequiresRestart = !PhotonMicrophoneEnumerator.IDIsValid(this.photonMicrophoneDeviceId); } else { this.RequiresRestart = !IsValidUnityMic(this.unityMicrophoneDevice); } if (this.RequiresRestart) { if (this.Logger.IsInfoEnabled) { this.Logger.LogInfo("Restarting Recording as the selected Photon microphone is no longer valid/available"); } this.RestartRecording(); } } }
private LocalVoice CreateLocalVoiceAudioAndSource() { switch (SourceType) { case InputSourceType.Microphone: { if (this.MicrophoneType == MicType.Photon) { #if UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX || UNITY_EDITOR_WIN var hwMicDev = this.PhotonMicrophoneDeviceId; if (this.Logger.IsInfoEnabled) { this.Logger.LogInfo("Setting recorder's source to Photon microphone device [{0}] \"{1}\"", hwMicDev, PhotonMicrophoneEnumerator.NameAtIndex(hwMicDev)); } #else if (this.Logger.IsInfoEnabled) { this.Logger.LogInfo("Setting recorder's source to Photon microphone device"); } #endif #if UNITY_STANDALONE_WIN && !UNITY_EDITOR || UNITY_EDITOR_WIN if (this.Logger.IsInfoEnabled) { this.Logger.LogInfo("Setting recorder's source to WindowsAudioInPusher"); } inputSource = new Windows.WindowsAudioInPusher(hwMicDev, this.Logger); #elif UNITY_IOS && !UNITY_EDITOR if (this.Logger.IsInfoEnabled) { this.Logger.LogInfo("Setting recorder's source to IOS.AudioInPusher with session {0}", audioSessionParameters); } inputSource = new IOS.AudioInPusher(audioSessionParameters, this.Logger); #elif UNITY_STANDALONE_OSX && !UNITY_EDITOR || UNITY_EDITOR_OSX if (this.Logger.IsInfoEnabled) { this.Logger.LogInfo("Setting recorder's source to MacOS.AudioInPusher"); } inputSource = new MacOS.AudioInPusher(hwMicDev, this.Logger); #elif UNITY_ANDROID && !UNITY_EDITOR if (this.Logger.IsInfoEnabled) { this.Logger.LogInfo("Setting recorder's source to UnityAndroidAudioInAEC"); } inputSource = new UnityAndroidAudioInAEC(this.Logger); #else inputSource = new AudioDesc(0, 0, "Photon microphone type is not supported for the current platform."); #endif if (inputSource.Error == null) { break; } if (this.Logger.IsErrorEnabled) { this.Logger.LogError("Photon microphone input source creation failure: {0}. Falling back to Unity microphone", inputSource.Error); } } if (Microphone.devices.Length < 1) { if (this.Logger.IsInfoEnabled) { this.Logger.LogInfo("No Microphone"); } return(LocalVoiceAudioDummy.Dummy); } var micDev = this.UnityMicrophoneDevice; if (this.Logger.IsInfoEnabled) { this.Logger.LogInfo("Setting recorder's source to Unity microphone device {0}", micDev); } // mic can ignore passed sampling rate and set its own inputSource = new MicWrapper(micDev, (int)SamplingRate, this.Logger); if (inputSource.Error != null && this.Logger.IsErrorEnabled) { this.Logger.LogError("Unity microphone input source creation failure: {0}.", inputSource.Error); } } break; case InputSourceType.AudioClip: { if (AudioClip == null) { if (this.Logger.IsErrorEnabled) { this.Logger.LogError("AudioClip property must be set for AudioClip audio source"); } return(LocalVoiceAudioDummy.Dummy); } inputSource = new AudioClipWrapper(AudioClip); // never fails, no need to check Error if (this.LoopAudioClip) { ((AudioClipWrapper)inputSource).Loop = true; } } break; case InputSourceType.Factory: { if (InputFactory == null) { if (this.Logger.IsErrorEnabled) { this.Logger.LogError("Recorder.InputFactory must be specified if Recorder.Source set to Factory"); } return(LocalVoiceAudioDummy.Dummy); } inputSource = InputFactory(); if (inputSource.Error != null && this.Logger.IsErrorEnabled) { this.Logger.LogError("InputFactory creation failure: {0}.", inputSource.Error); } } break; default: if (this.Logger.IsErrorEnabled) { this.Logger.LogError("unknown Source value {0}", SourceType); } return(LocalVoiceAudioDummy.Dummy); } if (this.inputSource == null || this.inputSource.Error != null) { return(LocalVoiceAudioDummy.Dummy); } VoiceInfo voiceInfo = VoiceInfo.CreateAudioOpus(SamplingRate, inputSource.Channels, FrameDuration, Bitrate, UserData); return(client.CreateLocalVoiceAudioFromSource(voiceInfo, inputSource, forceShort)); }