Fixed performance issue for system sounds and main volume

This commit is contained in:
dlprows 2023-09-13 20:46:05 -06:00
parent 1fea2a2e11
commit 06266daa92

View File

@ -54,6 +54,14 @@ public class AudioHelper
static object _lock = new object(); static object _lock = new object();
public void ResetCache()
{
lock(_lock)
{
_current = null;
}
}
public IAudioSession GetActiveSession(FallbackBehavior fallbackBehavior) public IAudioSession GetActiveSession(FallbackBehavior fallbackBehavior)
{ {
lock (_lock) lock (_lock)
@ -67,11 +75,11 @@ public class AudioHelper
if(_current == null) if(_current == null)
{ {
if(fallbackBehavior == FallbackBehavior.SystemSounds) if(fallbackBehavior == FallbackBehavior.SystemSounds && _current is not SystemSoundsAudioSession)
{ {
_current = GetSystemSounds(); _current = GetSystemSounds();
} }
else if(fallbackBehavior == FallbackBehavior.SystemVolume) else if(fallbackBehavior == FallbackBehavior.SystemVolume && _current is not SystemVolumeAudioSession)
{ {
_current = GetSystemVolume(); _current = GetSystemVolume();
} }