- Home /
Question by
Rimoldi · Jun 18, 2021 at 02:07 PM ·
mobilemicrophonedevice
Detect when external microphone is connected
I want my code to be notified when an external microphone is connected on mobile, is there any event that fires when a new device is connected?
I am currently doing this on Update:
private void WatchMicrophoneDevices()
{
if (Microphone.devices.Length > connectedMicrophoneDevices.Length)
{
OnExternalMicrophoneConnected?.Invoke(Microphone.devices[Microphone.devices.Length - 1]);
}
else if (Microphone.devices.Length < connectedMicrophoneDevices.Length)
{
string diconnectedDevice = connectedMicrophoneDevices.Where(d => !Microphone.devices.Contains(d)).FirstOrDefault();
OnExternalMicrophoneDisconnected?.Invoke(diconnectedDevice);
}
}
Comment