1

I'm using NAudio and the AudioSwitcher libary in my software. I want to change the volume for one audio device like in this picture:

enter image description here

Unfortunately I can't find a description how to get access to the volume controle in this mixer with one of the 2 libaries.

Is there anywhere a documentation for the libary or someone has an example for me?

So far I only managed to get access to this volume control but this is not the same like above

enter image description here

For the settings that I managed to work I use:

           IEnumerable<CoreAudioDevice> DeviceList = m_Controller.GetPlaybackDevices();

            foreach (CoreAudioDevice PlaybackDevice in DeviceList)
            {
                if (PlaybackDevice != null)
                {
                    if (PlaybackDevice.State == AudioSwitcher.AudioApi.DeviceState.Disabled)
                        continue;

                     string strTmp = PlaybackDevice.FullName.ToUpper();
                     if (PlaybackDevice.FullName.Contains("xxxxx"))
                     {
                         m_PlaybackDevice = PlaybackDevice;
                         m_PlaybackDevice.SetAsDefault();
                         m_PlaybackDevice.SetAsDefaultCommunications();
                         PlaybackDevice.SetVolumeAsync(100);
                    }
                }

            }

But it is not the volume setting from the first picture

Update 1:

I tried the link with the nAudio example

        try
        {

            NAudio.CoreAudioApi.MMDeviceEnumerator MMDE = new NAudio.CoreAudioApi.MMDeviceEnumerator();

            NAudio.CoreAudioApi.MMDeviceCollection DevCol = MMDE.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.All, NAudio.CoreAudioApi.DeviceState.All);

            foreach (NAudio.CoreAudioApi.MMDevice dev in DevCol)
            {
                try
                {

                    System.Diagnostics.Debug.Print(dev.FriendlyName);
                    //dev.AudioEndpointVolume.Mute = true;
                }
                catch (Exception ex)
                {
                    //Do something with exception when an audio endpoint could not be muted 
                }
            }
        }
        catch (Exception ex)
        {
            //When something happend that prevent us to iterate through the devices 
        }

But this gives me only a list of the hardware devices and not a list of the applications from my first picture. I need the application list. e.g. when firefox runs I could change the volume of the firefox app in that audio mixer panel.

Update 2

            NAudio.CoreAudioApi.MMDeviceEnumerator MMDE = new NAudio.CoreAudioApi.MMDeviceEnumerator();

throws sometimes, but not always an exception:

Blockquote System.InvalidCastException: Das Objekt des Typs "System.__ComObject" kann nicht in Typ NAudio.CoreAudioApi.Interfaces.MMDeviceEnumeratorComObject" umgewandelt werden.
bei NAudio.CoreAudioApi.MMDeviceEnumerator..ctor()

Sometimes it works but most times I get that cast exception

Fellnase
  • 103
  • 1
  • 9
  • Can you share what have you done so far? – Hasan Emrah Süngü Feb 04 '19 at 12:30
  • I can only add the part from the second picture where I can access the volume from the second picture. But for the first picture I have no idea how to access it – Fellnase Feb 04 '19 at 12:33
  • I havent used nAudio before but going to their github page I have found out that you need to use `GetDefaultAudioEndpoint` to set volume. Here is the page https://github.com/naudio/NAudio/blob/master/Docs/EnumerateOutputDevices.md – Hasan Emrah Süngü Feb 04 '19 at 12:39
  • But I don't want to get the defail device I want to set the volume from the first picture. It's also not clear to me what's the different to the volume from the first picture but it seems to be 2 different things because when I change the slider from the second pic it has no influence from the first one and the turn around – Fellnase Feb 04 '19 at 13:31
  • Have you seen this [related post](https://stackoverflow.com/a/51937972/1911064)? – Axel Kemper Feb 04 '19 at 13:48
  • No this is new to me, thank you I will try it :-) – Fellnase Feb 04 '19 at 15:58
  • I updated my post above, unfortunately that link didn't help – Fellnase Feb 04 '19 at 16:44
  • I found a solution. with NAudio I get crashes but with AudioSwitcher I can access the sessions and find my app to mute it – Fellnase Feb 07 '19 at 19:45

0 Answers0