修复 CoreAudioAPI

This commit is contained in:
ZouJin 2023-08-15 16:09:48 +10:00
parent 61080ac8e3
commit 74d2ff9e89

View File

@ -477,7 +477,7 @@ namespace VPet_Simulator.Windows
public float AudioPlayingVolume() public float AudioPlayingVolume()
{ {
if (AudioPlayingVolumeOK == null) if (AudioPlayingVolumeOK == null)
{ {//第一调用检查是否支持
try try
{ {
float vol = 0; float vol = 0;
@ -499,13 +499,20 @@ namespace VPet_Simulator.Windows
{ {
return -1; return -1;
} }
using (var enumerator = new MMDeviceEnumerator()) try
{ {//后续容错可能是偶发性
using (var meter = AudioMeterInformation.FromDevice(enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia))) using (var enumerator = new MMDeviceEnumerator())
{ {
return meter.GetPeakValue(); using (var meter = AudioMeterInformation.FromDevice(enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia)))
{
return meter.GetPeakValue();
}
} }
} }
catch
{
return -1;
}
} }
/// <summary> /// <summary>
/// 音乐检测器 /// 音乐检测器