Question How to control Speaker AND Headphone volume

DalMan

New member
Joined
Dec 16, 2015
Messages
2
Programming Experience
10+
I am new to this forum and to forum posting in general, so please forgive me in advance if I make a mistake in posting protocol. :sulkiness:

I have searched for the last several days for help on how to set the volume in my VB application, and I have found a lot of info about using the DefaultAudioEndpoint, which I am easily able to control - no problem. However, I can't seem to find an example of how to control the volume of both the speaker AND headphones, which becomes a particular problem when either is unplugged or plugged in while my application is running. Because these endpoints come and go from the windows sound Playback devices list, I keep ending up with no control over the volume. Can anyone please point me in the right direction for how this is supposed to be done? Thanks very much for any help.

John
 
I had hoped to have gotten some (any) responses to this, but I have solved this on my own. I needed to subscribe to the IMMDeviceEnumerator::RegisterEndpointNotificationCallback and enumerate the audioendpoints whenever there was a change. I found this wrapper and article at codeproject: Managed Wrapper around MMAudioDeviceApi - CodeProject


Here's what I did - maybe somebody else will need this:


Imports AudioDeviceUtil

Private WithEvents DeviceNotify As New AudioDeviceUtil.AudioDeviceManager

Public Sub Init()

AddHandler DeviceNotify.AudioDeviceEvent, AddressOf audioendpoint_OnChangeNotification
DeviceNotify.RegisterForNotification = True
.
.
End Sub

Public Sub audioendpoint_OnChangeNotification(sender as Object, e as AudioDeviceNotificationEventArgs)
Dim Params As Object() = New Object(0) {}
Params(0) = e
If Me.InvokeRequired Then
Me.Invoke(New AudioDeviceNotification.NotifyDelegate(AddressOf audioendpointchanged), Params)
Else
audioendpointchanged(e)
End If
End Sub

Public Sub audioendpointchanged(e as AudioDeviceNotificationEventArgs)
.
'Enumerate audio endpoints
.
End Sub
 
Last edited:

Latest posts

Back
Top