C# 如何判断系统是否是静音

推荐的方法,使用CoreAudioApi.dll,仅在win7上测试过:

        private MMDevice defaultDevice = null;
        //判断当前系统扬声器状态
        private bool IsMuted()
        {
            return defaultDevice.AudioEndpointVolume.Mute;
        }
        //静音
        private void SetMute()
        {
            defaultDevice.AudioEndpointVolume.Mute = true;
        }
        //解除静音 
        private void SetUnMute()
        {
            defaultDevice.AudioEndpointVolume.Mute = false;
        }
        //初始化MMDevice 
        private void MuteInit()
        {
            MMDeviceEnumerator devEnum = new MMDeviceEnumerator();
            defaultDevice = devEnum.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eMultimedia);
        }

 

posted @ 2015-11-03 10:21  沙耶  阅读(1548)  评论(0编辑  收藏  举报