Hi
I am trying to get an event when an audio device is plugged or unplugged
I was trying to use CoreAudio API I created ImmNotificationClient.cs interface
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace CoreAudioApi.Interfaces
{
/// <summary>
/// IMMNotificationClient
/// </summary>
[Guid("7991EEC9-7E89-4D85-8390-6C703CEC60C0"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IMMNotificationClient
{
/// <summary>
/// Device State Changed
/// </summary>
void OnDeviceStateChanged([MarshalAs(UnmanagedType.LPWStr)] string deviceId, [MarshalAs(UnmanagedType.I4)] EDeviceState newState);
/// <summary>
/// Device Added
/// </summary>
void OnDeviceAdded([MarshalAs(UnmanagedType.LPWStr)] string pwstrDeviceId);
/// <summary>
/// Device Removed
/// </summary>
void OnDeviceRemoved([MarshalAs(UnmanagedType.LPWStr)] string deviceId);
/// <summary>
/// Default Device Changed
/// </summary>
void OnDefaultDeviceChanged(EDataFlow flow, ERole role, [MarshalAs(UnmanagedType.LPWStr)] string defaultDeviceId);
/// <summary>
/// Property Value Changed
/// </summary>
/// <param name="pwstrDeviceId"></param>
/// <param name="key"></param>
void OnPropertyValueChanged([MarshalAs(UnmanagedType.LPWStr)] string pwstrDeviceId, PropertyKey key);
}
I have created CMMNotificationClient.cs class which implements above methods
Now I am not sure How to register the call back to these methods and register for Plug and UnPlug Events
I tried to register it in the IMMDeviceEnumerator
[PreserveSig]
int RegisterEndpointNotificationCallback(IMMNotificationClient pClient);
[PreserveSig]
int UnregisterEndpointNotificationCallback(IMMNotificationClient pClient);
Can you please help on this or can you provide any other solution
Thnaks
Gourav