[英]Changing soundcard and playing an MP3
I want to play an MP3 on a sound card other than the default (eg I plugged in a USB headset). 我想在非默认声卡上播放MP3(例如,我插入USB耳机)。
I have code that works perfectly fine if I want to play a WAV file on a different sound card. 如果要在其他声卡上播放WAV文件,我的代码可以很好地工作。 But with MP3, it just fails.
但是使用MP3,它只会失败。 I am trying to write the code in C#, but for the sake of there being nothing between the app and WinAPI (eg interop), I translated it to VB6.
我试图用C#编写代码,但是为了使应用程序和WinAPI之间没有任何关系(例如,互操作),我将其翻译为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
. 具体来说,失败的是更改声卡的调用-mciSendCommand-失败,并显示错误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 (eg change sound card, etc...), then play. MCI类型操作的顺序通常是这样的:打开文件,执行操作(例如,更改声卡等),然后播放。
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. 有趣的是,如果我要播放WAV文件,必须使用
waveaudio
而不是mpegvideo
打开它(例如,此cmd = "Open test.mp3 type waveaudio alias WAVFile"
),则一切正常。 But no matter what I tried it won't work if I try to open an MP3 file. 但是无论我尝试了什么,如果我尝试打开MP3文件都将无法使用。
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.
我已经看到了十二个这样的悬而未决的问题,可以追溯到2000年-必须有一种方法可以在其他声卡上播放MP3文件。
have you tried to change 你有没有尝试改变
cmd = "Open test.mp3 type mpegvideo alias Mp3File"
to 至
cmd = "Open test.mp3 type mpegvideo alias MediaFile"
? 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: 在CodeProject上查看使用.NET和Winmm.dll播放MP3文件的本文:
"MP3 Helper Class - http://www.codeproject.com/Articles/95000/MP3-Helper-Class" “ MP3帮助程序类-http://www.codeproject.com/Articles/95000/MP3-Helper-Class”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.