Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
播放MP3文件(C#表单)_C#_Forms_Audio_Mp3 - Fatal编程技术网

播放MP3文件(C#表单)

播放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

我正在试着播放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";
    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:我会试试。谢谢你的提示。