1

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.

AngryHacker
  • 59,598
  • 102
  • 325
  • 594
  • here is an ASM example mybe it can help you: http://www.rohitab.com/discuss/topic/9205-play-mpeg-mp3-avi-probably/ – Jester Dec 08 '12 at 06:22
  • this guy Dave looks like he ran into the same problem: http://www.itlisting.org/1-windows-media/911fe1683fd26cc4.aspx – Jeremy Thompson Dec 08 '12 at 06:55
  • @Jester The ASM example doesn't change the audio device where the mp3 file will play. It simply plays the file. That part works ok for me. Changing devices on which to play it - that is what's not working. – AngryHacker Dec 08 '12 at 07:18
  • you sure you are intializing all the fields of the `MCI_WAVE_SET_PARAMS` struct correctly/completely? http://msdn.microsoft.com/en-us/library/windows/desktop/dd798435(v=vs.85).aspx – Christian Westman Dec 08 '12 at 07:37
  • API declare of `mciSendCommand`, last param `As Any`? – wqw Dec 08 '12 at 12:28
  • @wqw Yes, the last param is Any. `Private Declare Function mciSendCommand Lib "winmm.dll" Alias _ "mciSendCommandA" (ByVal wDeviceID As Long, _ ByVal uMessage As Long, ByVal dwParam1 As Long, _ ByRef dwParam2 As Any) As Long` – AngryHacker Dec 10 '12 at 06:40
  • @ChristianWestman All usage of mciSendCommand I've seen in various examples, only populates wOutput member. The problem is that I don't really know what else needs to be populated and the documentation is pretty much non-existent. – AngryHacker Dec 10 '12 at 08:15

1 Answers1

0

have you tried to change

cmd = "Open test.mp3 type mpegvideo alias Mp3File"

to

cmd = "Open test.mp3 type mpegvideo alias MediaFile" ?

have a look at this article on CodeProject that uses .NET and Winmm.dll to play MP3 files:

"MP3 Helper Class - http://www.codeproject.com/Articles/95000/MP3-Helper-Class"

Christian Westman
  • 2,985
  • 1
  • 26
  • 28
  • The CodeProject is about playing the MP3 file which is no problem at all. The issue is changing the sound card which is (according to the docs) accomplished via mciSendCommand command and that is what fails whenever type `mpegvideo` is specified. The alias doesn't really matter (but for posterity I tried and it failed). – AngryHacker Dec 08 '12 at 07:13