【问题标题】:How to specify a sound card for use with mciSendString API如何指定与 mciSendString API 一起使用的声卡
【发布时间】:2019-01-08 10:50:46
【问题描述】:

我正在更新旧的 VB6 应用程序。过去,我围绕 mciSendString 命令编写了一个包装器,以便能够录制和播放音频。那时,计算机通常只有一个声卡。

现在,许多客户都有多个声卡(通常是内置的和 USB 耳机)。

我似乎找不到用于指定与 mciSendString 一起使用的声卡的 API。有人能指出我正确的方向吗?

【问题讨论】:

    标签: winapi vb6 audio mcisendstring


    【解决方案1】:

    请在此处查看带有源代码的几个解决方案(Ergebnisse des Wettbewerbs / 德语): http://www.activevb.de/rubriken/wettbewerbe/2009_september/comp_2009_september_mp3_player.html

    这里是我项目的一些来源

    ''' <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
    

    使用设备ID开始记录和使用。 希望有帮助

    【讨论】:

      【解决方案2】:

      微软提供了answer

      要设置多媒体控件使用的 WaveAudio 设备(声卡),您必须使用 mciSendCommand API。多媒体控件不直接提供让您设置用于播放或录制的设备的方法。

      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)
      

      【讨论】:

        猜你喜欢
        • 2012-12-06
        • 2019-09-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-01-12
        • 2016-07-25
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多