mirror of
https://github.com/LorisYounger/VPet.git
synced 2024-08-30 18:42:36 +00:00
针对音量识别失败的容错功能
This commit is contained in:
parent
24c07f7018
commit
b682f95ce1
@ -470,11 +470,35 @@ namespace VPet_Simulator.Windows
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private bool? AudioPlayingVolumeOK = null;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获得当前系统音乐播放音量
|
/// 获得当前系统音乐播放音量
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public float AudioPlayingVolume()
|
public float AudioPlayingVolume()
|
||||||
{
|
{
|
||||||
|
if (AudioPlayingVolumeOK == null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
float vol = 0;
|
||||||
|
using (var enumerator = new MMDeviceEnumerator())
|
||||||
|
{
|
||||||
|
using (var meter = AudioMeterInformation.FromDevice(enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia)))
|
||||||
|
{
|
||||||
|
vol = meter.GetPeakValue();
|
||||||
|
AudioPlayingVolumeOK = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
AudioPlayingVolumeOK = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (AudioPlayingVolumeOK == false)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
using (var enumerator = new MMDeviceEnumerator())
|
using (var enumerator = new MMDeviceEnumerator())
|
||||||
{
|
{
|
||||||
using (var meter = AudioMeterInformation.FromDevice(enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia)))
|
using (var meter = AudioMeterInformation.FromDevice(enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia)))
|
||||||
|
Loading…
Reference in New Issue
Block a user