Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Application volume is always set to 100 (for Flyleaf and all other windows applications started when Flyleaf running) #54

Closed
Spexxel opened this issue Aug 1, 2021 · 3 comments

Comments

@Spexxel
Copy link

Spexxel commented Aug 1, 2021

Describe the bug
Originally found in Race Control( robvdpol/RaceControl#195 and robvdpol/RaceControl#196), traced back to Flyleaf.
This bug has two sides to it.
With Windows Volume Mixer you can set the volume level for each individual application.

Problem 1:
When you set Flyleaf's volume in the mixer to something and reopen Flyleaf, the volume is always set back to 100.

Problem 2:
When Flyleaf is open the above problem also occurs for every other application you open which uses the same sound source.
This only happens to applications which get start after Flyleaf was started, so applications which were already running do not get reset.

To Reproduce
Steps to reproduce the behavior:

  1. Open an application, for this example Chrome
  2. Play something with sound through Chrome so that Windows recognizes it as sound output in the volume mixer
  3. Set the volume to something other than 100, for example to 30
  4. Open Flyleaf
  5. Close Chrome
  6. Open Chrome
  7. Play something with sound again.
  8. The volume is now reset to 100 because Flyleaf is open and now controlling all new audio sessions

Expected behavior
The expected behaviour is that the default behaviour for set volumes for the different application in the volume mixer do not get affected by Flyleaf.

Screenshots
Start situation:
image
After reproduction:
image

Additional context
Upon investigation in the code the problems occurs in AudioMaster.cs in the OnSessionCreated delegate:

device.AudioSessionManager.OnSessionCreated += (o, newSession) =>
{
if (session != null) { session.UnRegisterEventClient(this); session.Dispose(); }
session = new AudioSessionControl(newSession);
session.RegisterEventClient(this);
session.SimpleAudioVolume.Volume = 1;
Raise(nameof(VolumeSession));
Raise(nameof(MuteSession));
};

Here the volume will always be set to 1 (100);
session.SimpleAudioVolume.Volume = 1;

Once Flyleaf is running every new audio session will be caught by NAudio. This causes problem 2.
You can test this by setting a breakpoint in the above function and starting a any new application (which uses audio) while it is debugging.

I feel like it is not necessary to set the volume here since the default volume for windows applications will be set to 100 anyway.

A different way to fix this is to not handle the audio events which are not coming from Flyleaf (or applications which implement Flyleaf), but I think not setting the volume to 1 is way simpler for now.

@SuRGeoNix
Copy link
Owner

Well nice catch, thanks! Fixed it based on the process id which is more accurate solution. Thanks! (By the way by default the application session volume will start from the previous state)

@Spexxel
Copy link
Author

Spexxel commented Aug 2, 2021

Seems to work like a charm now, thanks for the quick fix! Is there going to be a release with this fix in it? If so, I can urge the other repo to update to the latest to include the fix :)

@SuRGeoNix
Copy link
Owner

As this is not urgent I will postpone it on v3.2 which will have a lot of changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants