I am updating an old VB6 app. Back in the day, I coded a wrapper around the mciSendString command to be able to record and playback audio. Back then, computers typically had a single audio card.
Now, many of the customers have multiple sound cards (typically a built in one and a USB headset).
I can't seem to find the API to specify which sound card to use with mciSendString. Can someone point me in开发者_如何学C the right direction?
Please check out several solutions here with sourcecode (Ergebnisse des Wettbewerbs / German): http://www.activevb.de/rubriken/wettbewerbe/2009_september/comp_2009_september_mp3_player.html
Here some source of my project
''' <summary>
''' Return all audio devices by names
''' </summary>
Private Function ListSoundDevices(ByRef LDev As List(Of String)) As Boolean
Dim intItem As New Integer
Dim intNext As New Integer
Dim intCount As New Integer
Dim tWIC As New WaveInCaps
Dim Enc As System.Text.ASCIIEncoding = New System.Text.ASCIIEncoding()
Dim res As Boolean = False
Try
'Throw New Exception("test")
intCount = waveInGetNumDevs()
Catch ex As Exception
'no devices found
Return False
End Try
If intCount <> 0 Then
For intItem = 0 To intCount - 1
If waveInGetDevCaps(intItem, tWIC, Marshal.SizeOf(tWIC)) = MMSYSERR_NOERROR Then
If (tWIC.Formats And WAVE_FORMAT_4S16) = WAVE_FORMAT_4S16 Then
If LDev Is Nothing Then LDev = New List(Of String)
Dim B() As Byte = System.Text.Encoding.Default.GetBytes(tWIC.ProductName.ToString.ToCharArray)
LDev.Add(Enc.GetString(B, 0, B.Length))
intNext += 1
End If
End If
Next
If intNext > 0 Then res = True
End If
Return res
End Function
Use the device ID to start record and using. Hope that helps
Microsoft has provided the answer.
To set the WaveAudio device (soundcard) used by the Multimedia Control, you must use the mciSendCommand API. The Multimedia Control does not directly provide a method to let you set the device used for playing or recording.
Dim parms As MCI_WAVE_SET_PARMS
Dim rc As Long
' Specify the soundcard. This specifies the soundcard with a deviceID
' of 0. If you have a single soundcard, then this will open it. If you
' have multiple soundcards, the deviceIDs will be 0, 1, 2, etc.
parms.wOutput = 0
' Send the MCI command to set the output device.
rc = mciSendCommand(MMControl1.DeviceID, MCI_SET, MCI_WAVE_OUTPUT, parms)
精彩评论