I want to control other application volume(firefox).
i can do it with Volume Mixer
What is the libraries of the Volume Mixer
?
I want to control other application volume(firefox).
i can do it with Volume Mixer
What is the libraries of the Volume Mixer
?
Here is a sample C# Console Application that does it. It's based on the Windows Core Audio Library. It works only on Windows 7 and higher.
using System; using System.Runtime.InteropServices; using System.Collections.Generic; namespace SetAppVolumne { class Program { static void Main(string[] args) { const string app = "Mozilla Firefox"; foreach (string name in EnumerateApplications()) { Console.WriteLine("name:" + name); if (name == app) { // display mute state & volume level (% of master) Console.WriteLine("Mute:" + GetApplicationMute(app)); Console.WriteLine("Volume:" + GetApplicationVolume(app)); // mute the application SetApplicationMute(app, true); // set the volume to half of master volume (50%) SetApplicationVolume(app, 50); } } } public static float? GetApplicationVolume(string name) { ISimpleAudioVolume volume = GetVolumeObject(name); if (volume == null) return null; float level; volume.GetMasterVolume(out level); return level * 100; } public static bool? GetApplicationMute(string name) { ISimpleAudioVolume volume = GetVolumeObject(name); if (volume == null) return null; bool mute; volume.GetMute(out mute); return mute; } public static void SetApplicationVolume(string name, float level) { ISimpleAudioVolume volume = GetVolumeObject(name); if (volume == null) return; Guid guid = Guid.Empty; volume.SetMasterVolume(level / 100, ref guid); } public static void SetApplicationMute(string name, bool mute) { ISimpleAudioVolume volume = GetVolumeObject(name); if (volume == null) return; Guid guid = Guid.Empty; volume.SetMute(mute, ref guid); } public static IEnumerable EnumerateApplications() { // get the speakers (1st render + multimedia) device IMMDeviceEnumerator deviceEnumerator = (IMMDeviceEnumerator)(new MMDeviceEnumerator()); IMMDevice speakers; deviceEnumerator.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eMultimedia, out speakers); // activate the session manager. we need the enumerator Guid IID_IAudioSessionManager2 = typeof(IAudioSessionManager2).GUID; object o; speakers.Activate(ref IID_IAudioSessionManager2, 0, IntPtr.Zero, out o); IAudioSessionManager2 mgr = (IAudioSessionManager2)o; // enumerate sessions for on this device IAudioSessionEnumerator sessionEnumerator; mgr.GetSessionEnumerator(out sessionEnumerator); int count; sessionEnumerator.GetCount(out count); for (int i = 0; i
Note: I have not defined the interfaces completely, only what was needed for the code to work.