I want to play an MP3 on a sound card other than the default (e.g. I plugged in a USB headset).
I have code that works perfectly fine if I want to play a WAV file on a different sound card. But with MP3, it just fails. I am trying to write the code in C#, but for the sake of there being nothing between the app and WinAPI (e.g. interop), I translated it to VB6. Specifically, what fails is the call to change the sound card - mciSendCommand - and it fails with error 274 - The MCI device you are using does not support the specified command
. The sequence with the MCI type operations is typically like this: Open File, Do Operations (e.g. change sound card, etc...), then play.
Dim cmd as String
Dim rc as Long
Dim lngDeviceID As Long
Dim parms As MCI_WAVE_SET_PARMS
cmd = "Open test.mp3 type mpegvideo alias Mp3File"
rc = mciSendString(CommandString, vbNullString, 0, 0&) ' Open works
lngDeviceID = mciGetDeviceID("Mp3File")
parms.wOutput = 1 ' tell it to playback on the 2nd card
rc = mciSendCommand(lngDeviceID, MCI_SET, MCI_WAVE_OUTPUT, parms) ' FAILS with 274
If (rc <> MMSYSERR_NOERROR) Then
' The command failed.
MsgBox "Change card: " & GetMCIErrorString(rc)
End If
Interestingly, if I want to play a WAV file, for which I have to open it with waveaudio
instead of mpegvideo
(like this cmd = "Open test.mp3 type waveaudio alias WAVFile"
), everything works fine. But no matter what I tried it won't work if I try to open an MP3 file.
What am I missing? I've seen a dozen unanswered questions like this going back to 2000 - there has to be a way to play an MP3 file on a different sound card.