我正在尝试播放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);
}
关于c# - 播放MP3文件(C#表格),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26557532/