How to specify a sound card for use with mciSendString API

旧城冷巷雨未停 提交于 2021-01-27 19:42:03

问题


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 the right direction?


回答1:


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




回答2:


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)


来源:https://stackoverflow.com/questions/6235179/how-to-specify-a-sound-card-for-use-with-mcisendstring-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!