如何通过特定的声卡播放音频? [英] How to play audio via a specific sound card?

查看:56
本文介绍了如何通过特定的声卡播放音频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从Visual Basic 6应用程序播放声音(.WAV文件).但是,该PC配备了多个声卡,用户应该可以使用它.

I need to play a sound (.WAV file) from a Visual Basic 6 application. However, the PC is equipped with multiple sound cards and the user should be able to use it.

到目前为止,支持默认的声卡,我将播放这样的声音:

Up till now a default sound card was supported and I would play a sound like this:

CommandString = "Open " & Chr$(34) & mstrFilename & Chr$(34) & " type waveaudio alias MediaFile"
mciSendString CommandString, vbNullString, 0, 0&

If PlayFromPercent <= 0 Then
    CommandString = "play MediaFile"
    lngRetcode = mciSendString(CommandString, vbNullString, 0, 0&)
Else
    CommandString = "play MediaFile from " & CLng(lngLength * (PlayFromPercent / 100))
    lngRetcode = mciSendString(CommandString, vbNullString, 0, 0&)
End If

有没有办法针对特定的声卡修改此代码,或者我可以采用其他方法(例如DirectX或商业的3rd Party Library)?

Is there a way to adapt this code for a specific sound card or is there a different approach I could take (e.g. DirectX or a commercial 3rd Party Library)?

奖金,如果该方法支持从特定位置播放文件(如您所见,上面的代码支持该文件)

Bonus, if the approach supports playing the file from a specific position (as you can see, the code above supports it)

推荐答案

这可能有效;调用 mciSendCommand() MCI_SET & MCI_WAVE_SET_PARMS wOutput 设置为所需的播放设备的ID.

This may work; call mciSendCommand() with MCI_SET & MCI_WAVE_SET_PARMS setting wOutput to the desired playback device's ID.

  • 您可以通过 mciGetDeviceID("waveaudio")
  • 获取 mciSendCommand() IDDevice
  • 尚不能100%清楚地知道 wOutput 想要什么,它的ID可能与 waveOutGetDevCaps()
  • 返回的ID相同
  • You can get IDDevice for mciSendCommand() via mciGetDeviceID("waveaudio")
  • Its not 100% clear what wOutput wants, its probably the same ID as returned by waveOutGetDevCaps()

这篇关于如何通过特定的声卡播放音频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆