Home > Net >  C # hotplug monitoring audio equipment
C # hotplug monitoring audio equipment

Time:11-05

Win10 system can real-time detect the headphones plug, saw a lot of information about NAUDIO online, did not fix, which eldest brother do you have any code can run directly for reference, thanks!

CodePudding user response:

Class Program
{
Private NAudio. CoreAudioApi. MMDeviceEnumerator deviceEnum=new NAudio. CoreAudioApi. MMDeviceEnumerator ();
Private NotificationClientImplementation notificationClient;
Private NAudio. CoreAudioApi. Interfaces. IMMNotificationClient notifyClient;


///& lt; Summary>
///Registers a call back for Device Events
///& lt;/summary>
///& lt; Param name="client" & gt; The Object implementing IMMNotificationClient type casted as IMMNotificationClient interface
///& lt; Returns>
Public int RegisterEndpointNotificationCallback ([In] [MarshalAs (UnmanagedType. Interface)] IMMNotificationClient client)//MarshalAs also error, there is no corresponding using
{
//DeviceEnum declared below
Return deviceEnum. RegisterEndpointNotificationCallback (the client);
// RegisterEndpointNotificationCallback here can't find the corresponding types in deviceEnum
}


The static void Main (string [] args)
{
Var enumerator=new NAudio. CoreAudioApi. MMDeviceEnumerator ();

//Allows you to enumerate rendering devices in certain states
Var endpoints=enumerator. EnumerateAudioEndPoints (
DataFlow. Render,
DeviceState. Unplugged | DeviceState. Active);
The foreach (var endpoint in endpoints)
{
Console. WriteLine (" {0} - {1} ", the endpoint. DeviceFriendlyName, endpoint. The State);
}
Console. WriteLine (" check now ");
//Aswell as the hooks to the actual event
Enumerator. RegisterEndpointNotificationCallback (new NotificationClient ());
//enumerator. GetDefaultAudioEndpoint (endpoint DeviceFriendlyName, endpoint. The State);
The Console. ReadLine ();
}

CodePudding user response:

With VLC played before specified sound card
  •  Tags:  
  • C #
  • Related