none
Turn down music RRS feed

  • Question

  • Hello

    I'm developing in .net C# an addition software for 3CX phone system. I also need to connect my work with Skype Webportal. 

    The issue here is that I need to develop an action who turn down music and another sounds when 3CX phone system rings in the computer. Similar as Skype for Business is able to do.

    But the problem is I don't want to turn down complete in the audio because the user needs to hear the caller. The only thing that I want to do is to determine if someone is using software like web radio, podcast, Spotify etc. and turn that down instead of turn the whole volume down in the computer. So the sound will only come through 3CX, not another software. 

    Is there a base class who is able to do that or can anyone advise me about workaround in this issue?


    Sigurður H Alfhildars

    Wednesday, November 21, 2018 3:17 PM

All replies

  • Hi Sandri81,

    Please try the following method by using windows API.

    [DllImport("winmm.dll")]
    private static extern int waveOutGetVolume(IntPtr hwo, out uint dwVolume);
    
    [DllImport("winmm.dll")]
    private static extern int waveOutSetVolume(IntPtr hwo, uint dwVolume);
    
    /// <summary>
    /// Returns volume from 0 to 10
    /// </summary>
    /// <returns>Volume from 0 to 10</returns>
    public static int GetVolume()
    {
      uint CurrVol = 0;
      waveOutGetVolume(IntPtr.Zero, out CurrVol);
      ushort CalcVol = (ushort)(CurrVol & 0x0000ffff);
      int volume = CalcVol / (ushort.MaxValue / 10);
      return volume;
    }
    
    /// <summary>
    /// Sets volume from 0 to 10
    /// </summary>
    /// <param name="volume">Volume from 0 to 10</param>
    public static void SetVolume(int volume)
    {
      int NewVolume = ((ushort.MaxValue / 10) * volume);
      uint NewVolumeAllChannels = (((uint)NewVolume & 0x0000ffff) | ((uint)NewVolume << 16));
      waveOutSetVolume(IntPtr.Zero, NewVolumeAllChannels);
    }
    

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, November 22, 2018 2:03 AM
    Moderator
  • Here's how you can control per-application volume by process ID.
    Thursday, November 22, 2018 2:47 AM
    Answerer
  • With this code I can move the slider in the sound mixer, corresponding to the app i execute the code in. That is great, however the sound keeps playing at the same level. If i move the slider with the mouse the sound immediately jumps to the sound level indicated by the slider.

    It seems I need to do some sort of apply after executing the waveOutSetVolume function.

    Any input on how to apply the new sound level would be appreciated.

    Thursday, May 23, 2019 8:13 AM