How to play audio via a specific sound card?

可紊 提交于 2021-02-11 06:43:33

问题


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

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)


回答1:


This may work; call mciSendCommand() with MCI_SET & MCI_WAVE_SET_PARMS setting wOutput to the desired playback device's 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()


来源:https://stackoverflow.com/questions/10958622/how-to-play-audio-via-a-specific-sound-card

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