解决方案 »

  1.   

    经过多天的资料查找,问题解决了。现留个脚印,结贴!
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Runtime.InteropServices;
    using CoreAudio.Interfaces;
    using CoreAudio;namespace AudioEnginHelper_Clbrt
    {
        //Small wrapper class
        public class MMNotificationClient : IMMNotificationClient
        {
            public DeviceStateChangedDelegate dvMicChangedDlgt;
            public DeviceStateChangedDelegate dvSpkChangedDlgt;        MMDeviceEnumerator DevEnum = null;
            public MMNotificationClient()
            {
                DevEnum = new MMDeviceEnumerator();
                DevEnum.RegisterEndpointNotificationCallback(this); 
            }                public void OnDeviceStateChanged([In, MarshalAs(UnmanagedType.LPWStr)] string pwstrDeviceId, DEVICE_STATE dwNewState)
            {
                if (null != DevEnum)
                {
                    MMDevice mMDevice = DevEnum.GetDevice(pwstrDeviceId);
                    if (null != mMDevice)
                    {
                        switch (mMDevice.DataFlow)
                        {
                            case EDataFlow.eRender:
                                {
                                    dvSpkChangedDlgt();
                                }
                                break;
                            case EDataFlow.eCapture:
                                {
                                    dvMicChangedDlgt();
                                }
                                break;
                            default:
                                {
                                    dvSpkChangedDlgt();
                                    dvMicChangedDlgt();
                                }
                                break;
                        }
                    }
                }
            }       
        }
    }用到的开源库请到本人的资源中下载。
      

  2.   

    您好, 可否教我如何創建一DeviceStateChangedDelegate ?
    感謝