NAudio Mute帮助:无法转换类型为&System;。的系统.__ ComObject'键入' NAudio.CoreAudioApi.Interfaces.MMDeviceEnumeratorComObject'

时间:2018-05-10 11:57:58

标签: c# winforms

我一直在寻找一种方法来检查我的系统音频是否静音,而我能想出的就是:

        NAudio.CoreAudioApi.MMDeviceEnumerator devenum = new NAudio.CoreAudioApi.MMDeviceEnumerator();
        NAudio.CoreAudioApi.MMDevice device = devenum.GetDefaultAudioEndpoint(NAudio.CoreAudioApi.DataFlow.Render, NAudio.CoreAudioApi.Role.Multimedia);

        if (device.AudioEndpointVolume.Mute == true)
        {
            return true;
            SendMessageW(this.Handle, WM_APPCOMMAND, this.Handle,
                (IntPtr)APPCOMMAND_VOLUME_MUTE);
        }

        else
        {
            return false;
            SendMessageW(this.Handle, WM_APPCOMMAND, this.Handle,
                (IntPtr)APPCOMMAND_VOLUME_MUTE);
        }   

静音切换效果很好,但是 NAudio.CoreAudioApi.MMDeviceEnumerator devenum = new NAudio.CoreAudioApi.MMDeviceEnumerator(); NAudio.CoreAudioApi.MMDevice device = devenum.GetDefaultAudioEndpoint(NAudio.CoreAudioApi.DataFlow.Render, NAudio.CoreAudioApi.Role.Multimedia); 我尝试使用它后给了我错误:Unable to cast object of type 'System.__ComObject' to type 'NAudio.CoreAudioApi.Interfaces.MMDeviceEnumeratorComObject'.

注意:我是初学者,我需要一段时间才能理解最简单的事情。

0 个答案:

没有答案