我目前正在使用 C# 开发 MP3 播放器。我是初学者。我已经能够开发出具有最小功能的普通 MP3 播放器,例如打开文件、暂停、播放和停止。但问题是它播放了一些歌曲而没有播放一些歌曲。我也导入了 winmm.dll 文件。但是有些文件可以播放,而有些则没有。此外,任何人都可以建议我如何向其中添加一堆随机播放的歌曲?代码是:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
namespace MP3Player
{
class MusicPlayer
{
Boolean isPlay=false;
[DllImport("winmm.dll")]
private static extern long mciSendString(string lpstrCommand, StringBuilder lpstrReturnString, int uReturnLength, int hwndCallback);
public void open(String file)
{
string command = "open \"" + file + "\" type MPEGVideo alias MyMp3";
mciSendString(command, null, 0, 0);
isPlay = false;
}
public void play()
{
if (isPlay == false)
{
string command = "play MyMP3";
mciSendString(command, null, 0, 0);
isPlay = true;
}
}
public void pause()
{
if (isPlay == true)
{
string command = "pause MyMP3";
mciSendString(command, null, 0, 0);
isPlay = false;
}
}
public void stop()
{
string command = "stop MyMp3";
mciSendString(command, null, 0, 0);
isPlay = false;
command = "close MyMp3";
mciSendString(command, null, 0, 0);
}
}
}