播放MP3文件(C#表单)
我正在试着播放MP3的声音。我参考了MediaPlayer(Interop.MediaPlayer.dll和Interop.WMPLib.dll)。那么我有这个密码播放MP3文件(C#表单),c#,forms,audio,mp3,C#,Forms,Audio,Mp3,我正在试着播放MP3的声音。我参考了MediaPlayer(Interop.MediaPlayer.dll和Interop.WMPLib.dll)。那么我有这个密码 private void Main_Load(object sender, EventArgs e) { WMPLib.WindowsMediaPlayer wplayer = new WMPLib.WindowsMediaPlayer(); wplayer.URL = @"D:\test.mp3"; wpl
private void Main_Load(object sender, EventArgs e)
{
WMPLib.WindowsMediaPlayer wplayer = new WMPLib.WindowsMediaPlayer();
wplayer.URL = @"D:\test.mp3";
wplayer.controls.play();
}
我没有错误,但我一点声音也没有。。。另外,是否可以在不向应用程序文件夹中添加任何.dll的情况下播放MP3声音?我过去曾使用以下代码从C#播放MP3文件。我不确定这是否需要向应用程序文件夹添加任何DLL。我必须创建一个新项目来测试它
[DllImport("winmm.dll")]
private static extern long mciSendString(string lpstrCommand, StringBuilder lpstrReturnString, int uReturnLength, int hwndCallback);
public void playMP3File(string fileName)
{
string CommandString = "open " + "\"" + fileName + "\"" + " type MPEGVideo alias Mp3File";
mciSendString(CommandString, null, 0, 0);
CommandString = "play Mp3File";
mciSendString(CommandString, null, 0, 0);
}
你的代码应该播放。检查你的音量。如果你不能让它工作,我建议使用NAudio而不是MediaPlayer:我会试试。谢谢你的提示。