不是:
- 退訂
- 變化體積/設置靜音
- 重新訂閱
我修改邏輯以在性能基本上使用邏輯與支持字段時管理更新。這並不完美,但它非常貼心,並且不會消耗任何CPU,並且它允許來自滑塊的外部輸入,並且完全支持INPC。
public EndpointVolumeEnforcer() {
try {
mmDeviceEnumerator = new MMDeviceEnumerator();
mmDevice = mmDeviceEnumerator.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eMultimedia);
audioEndpointVolume = mmDevice.AudioEndpointVolume;
audioEndpointVolume.OnVolumeNotification += data => {
VolumePercent = Convert.ToInt16(data.MasterVolume*100);
DeviceIsMuted = data.Muted;
};
DesiredVolume = 65;
}
catch (Exception ex) {
// Logging logic here
}
}
public int DesiredVolume {
get { return _desiredVolume; }
private set {
if (_desiredVolume == value) return;
_desiredVolume = value;
NotifyOfPropertyChange();
Enforce(_desiredVolume);
}
}
public int VolumePercent {
get { return volumePercent; }
private set {
if (volumePercent == value) return;
volumePercent = value;
if (volumePercent != _desiredVolume) {
volumePercent = _desiredVolume;
Enforce(volumePercent);
}
}
}
public void Enforce(int pct, bool mute = false) {
var adjusted = Convert.ToInt16(audioEndpointVolume.MasterVolumeLevelScalar*100);
if (adjusted != DesiredVolume) {
audioEndpointVolume.MasterVolumeLevelScalar = pct/100f;
}
}
爲什麼不清楚正在讀取什麼註冊表項? Process Monitor應該爲您提供這些信息。可能有幫助。另外,你是否嘗試調試explorer.exe? – Simon
@Simon我很抱歉沒有注意到你的評論。我無法找到任何特定的按鍵,我對ProcMon並不熟悉。我將爲可能遇到相同問題的用戶發佈解決方法。 – erodewald