
Core Audio Demos
A few days ago I released the latest version of my oleexp typelib containing all of the Core Audio interfaces. Here's a demo of some of the basic features.
All of the functions shown in the above screenshot work, and additionally the 'Mute Default Multimedia Device' button also demonstrates how to set a callback for that device-- if any other app, like the volume mixer, then unmutes or does something else with that device, your app will be notified of the change. Note that all interfaces used for the callback must be module-level and not released while the callback is active, otherwise your app will freeze.
Requirements
-Windows Vista or higher
-oleexp v3.6 (released 16 May 2016): Add oleexp3.tlb as a reference-- for IDE only, does not need to be redistributed with compiled app.
-All 3 oleexp addons: mCoreAudio.bas, mIID.bas, and mPKEY.bas (all of which are now included in main oleexp download, and all were updated with v3.6 with Core Audio related code. They're also included in this project's zip, although oleexp3.tlb is not).
Code Example: Muting all active capture devices (e.g. microphones)
Code:
Dim sOut As String
Dim i As Long
Dim lp As Long
Dim s1 As String
Dim sName As String
Dim pDvEnum As MMDeviceEnumerator
Set pDvEnum = New MMDeviceEnumerator
Dim pDvCol As IMMDeviceCollection
pDvEnum.EnumAudioEndpoints eCapture, DEVICE_STATE_ACTIVE, pDvCol
If (pDvCol Is Nothing) = False Then
Dim nCount As Long
Dim pDevice As IMMDevice
If pDvCol.GetCount(nCount) = S_OK Then
If nCount > 0 Then
For i = 0 To (nCount - 1)
sName = GetDeviceName(pDvCol, i)
sOut = sOut & "Muting Device(" & i & ", Name=" & sName & ")..." & vbCrLf
pDvCol.Item i, pDevice
If (pDevice Is Nothing) = False Then
Dim pAEV As IAudioEndpointVolume
pDevice.Activate IID_IAudioEndpointVolume, CLSCTX_INPROC_SERVER, CVar(0), pAEV
If (pAEV Is Nothing) = False Then
If pAEV.SetMute(1, UUID_NULL) = S_OK Then
sOut = sOut & "...Device successfully muted!" & vbCrLf
Else
sOut = sOut & "...Failed to mute device " & i & " (" & sName & "). Already muted?" & vbCrLf
End If
Else
Debug.Print "Failed to set pAEV"
sOut = sOut & "...An error occured accessing the volume control." & vbCrLf
End If
Else
Debug.Print "Failed to set pDevice"
sOut = sOut & "...Failed to get pointer to device." & vbCrLf
End If
Next
Else
sOut = "No active devices found." & vbCrLf
End If
Else
Debug.Print "Failed to get device count."
sOut = sOut & "An error occured getting the device count." & vbCrLf
End If
Else
Debug.Print "Failed to set pDvCol"
sOut = "Failed to get device collection (no active devices or an error occured)"
End If
Text1.Text = sOut