我需要有关执行 mp3 播放器文件的帮助。我在互联网上搜索,发现只有在需要从外部目录获取 mp3 文件时如何使用 winmm.dll 库。我需要为我的应用程序的内部目录修改它。
让我们展示一下代码:
我像这样创建 Mp3Player 类:
class Mp3Player : IDisposable
{
[DllImport("winmm.dll")]
private static extern long mciSendString(string lpstrCommand, StringBuilder lpstrReturnString, int uReturnLength, int hwndCallback);
public void open(string file)
{
const string FORMAT = @"open ""{0}"" type MPEGVideo alias MyMp3";
string command = String.Format(FORMAT, file);
mciSendString(command, null, 0, 0);
}
public void play()
{
string command = "play MyMp3";
mciSendString(command, null, 0, 0);
}
public void stop()
{
string command = "stop MyMp3";
mciSendString(command, null, 0, 0);
}
public void Dispose()
{
string command = "close MyMp3";
mciSendString(command, null, 0, 0);
}
public double Duration()
{
string command = "status MyMp3 length";
double bho = mciSendString(command, null, 0, 0);
return bho;
}
并要求在此处打开内部文件:
var soundfile = "Assets/audio/myaudio.mp3";
private Mp3Player _mp3player = new Mp3Player();
_mp3player.open(soundfile);
_mp3player.play();
这在打开文件时给我一个错误,所以我确定问题出在我发送给班级的目录路径中。我尝试了一些版本,但没有人工作,在互联网上找不到任何帮助我的东西。你们中的一些人可以告诉我使工作发挥作用的正确途径吗?
非常感谢大家。
对不起,我的英语真的很糟糕。