As explained here, you need to call SetChannelVolumeLevel
or SetChannelVolumeLevelScalar
method of IAudioEndpointVolume
. The interop method is included in this Gist, but it is missing a convenient wrapper method.
For getting started, you need to include the C# code in PowerShell using Add-Type
:
Add-Type -TypeDefinition @'
-paste C# code here-
'@
Add this method to class AudioManager
:
/// <summary>
/// Sets the channel volume to a specific level
/// </summary>
/// <param name="channelNumber">Channel number, which can be 0..(numberOfChannels-1)</param>
/// <param name="newLevel">Value between 0 and 100 indicating the desired scalar value of the volume</param>
public static void SetChannelVolumeLevel(uint channelNumber, float newLevel)
{
IAudioEndpointVolume masterVol = null;
try
{
masterVol = GetMasterVolumeObject();
if (masterVol == null)
return;
masterVol.SetChannelVolumeLevelScalar(channelNumber, newLevel/100, Guid.Empty);
}
finally
{
if (masterVol != null)
Marshal.ReleaseComObject(masterVol);
}
}
I've inserted it before line private static IAudioEndpointVolume GetMasterVolumeObject()
, but it doesn't really matter where you put it within the class.
Now you can call it from PowerShell like this:
[VideoPlayerController.AudioManager]::SetChannelVolumeLevelScalar(0, 60)
[VideoPlayerController.AudioManager]::SetChannelVolumeLevelScalar(1, 40)
On my system it moves both left and right volume equally but I propably suffer from locked balance. There is a registry tweak described here which didn't work for me though.