c#对声音系统的控制
private MMDevice defaultDevice = null;
//參考資料
// http://www.codeproject.com/KB/vista/CoreAudio.aspx?msg=2747721
//
//判斷當前系統揚聲器狀態
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);
}
public MainWindow()
{
InitializeComponent();
muteInit();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
setUnMute();
//defaultDevice.AudioEndpointVolume.VolumeStepUp();
//defaultDevice.AudioEndpointVolume.MasterVolumeLevel =0.5f;
defaultDevice.AudioEndpointVolume.MasterVolumeLevelScalar = 0.5f;//调节音量
//MessageBox.Show(defaultDevice.AudioEndpointVolume.MasterVolumeLevelScalar.ToString());
//MessageBox.Show(defaultDevice.AudioEndpointVolume.MasterVolumeLevel.ToString());
}