如何通过特定的声卡播放音频?
我需要从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")
获取 - 尚不能100%清楚地知道
wOutput
想要什么,它的ID可能与waveOutGetDevCaps()
返回的ID相同
mciSendCommand()
的 IDDevice
- You can get
IDDevice
formciSendCommand()
viamciGetDeviceID("waveaudio")
- Its not 100% clear what
wOutput
wants, its probably the same ID as returned bywaveOutGetDevCaps()