win10系統下能實時偵測耳機插拔, 看了網上好多關于NAUDIO的資料,還是沒有搞定。 哪位大哥有沒有可以直接運行的代碼提供參考一下,感謝!
uj5u.com熱心網友回復:
class Program{
private NAudio.CoreAudioApi.MMDeviceEnumerator deviceEnum = new NAudio.CoreAudioApi.MMDeviceEnumerator();
private NotificationClientImplementation notificationClient;
private NAudio.CoreAudioApi.Interfaces.IMMNotificationClient notifyClient;
/// <summary>
/// Registers a call back for Device Events
/// </summary>
/// <param name="client">Object implementing IMMNotificationClient type casted as IMMNotificationClient interface</param>
/// <returns></returns>
public int RegisterEndpointNotificationCallback([In] [MarshalAs(UnmanagedType.Interface)] IMMNotificationClient client) //MarshalAs 也報錯,沒有相應的using
{
//DeviceEnum declared below
return deviceEnum.RegisterEndpointNotificationCallback(client);
//此處RegisterEndpointNotificationCallback在deviceEnum中找不到對應的型別
}
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);
foreach (var endpoint in endpoints)
{
Console.WriteLine("{0} - {1}", endpoint.DeviceFriendlyName, endpoint.State);
}
Console.WriteLine("check now");
// Aswell as hook to the actual event
enumerator.RegisterEndpointNotificationCallback(new NotificationClient());
// enumerator.GetDefaultAudioEndpoint(endpoint.DeviceFriendlyName, endpoint.State);
Console.ReadLine();
}
uj5u.com熱心網友回復:
以前用vlc玩過指定聲卡播放的轉載請註明出處,本文鏈接:https://www.uj5u.com/net/9845.html
標籤:C#
上一篇:AspNetPager 分頁控制元件Datalist 怎么實作
下一篇:GridView相關
