播放MP3文件(C#格式)
本文关键字:格式 MP3 文件 播放 | 更新日期: 2023-09-27 18:27:50
我正在尝试播放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);
}