问题
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
formciSendCommand()
viamciGetDeviceID("waveaudio")
- Its not 100% clear what
wOutput
wants, its probably the same ID as returned bywaveOutGetDevCaps()
来源:https://stackoverflow.com/questions/10958622/how-to-play-audio-via-a-specific-sound-card