我正在使用 winmm.dll 使用 C# 开发 mp3 播放器
我的倒带功能现在有问题。
当播放功能启动时,我启动了一个计时器。
当我启动 FFW 函数时,我希望它距离 elapsedTime 的当前值 5000 毫秒。
例如,如果我开始播放歌曲并在歌曲中按 FFW 6 秒,则播放应在 6000 毫秒 + 5000 毫秒(ffw5 秒)处继续。
但什么都没有发生。这次我做错了什么?
namespace kTP
{
public class MusicPlayer
{
[DllImport("winmm.dll")]
private static extern long mciSendString(string lpstrCommand, StringBuilder lpstrReturnString, int uReturnLength, int hwndCallback);
private bool isPlaying = false;
private int ffw5sec = 5000;
Timer elapsedTime = new Timer();
public void Open(string file)
{
string command = "open \"" + file + "\" type MPEGVideo alias MyMp3";
mciSendString(command, null, 0, 0);
}
public void Play()
{
isPlaying = true;
elapsedTime.Start();
elapsedTime.Interval = (1000);
string command = "play MyMp3";
mciSendString(command, null, 0, 0);
}
public void Pause()
{
isPlaying = false;
string command = "pause MyMp3";
mciSendString(command, null, 0, 0);
}
public void Stop()
{
isPlaying = false;
string command = "stop MyMp3";
mciSendString(command, null, 0, 0);
elapsedTime.Stop();
command = "close MyMp3";
mciSendString(command, null, 0, 0);
}
// return to start of song and resume playback
public void ReturnToStart()
{
isPlaying = true;
string command = "seek MyMp3 to start";
mciSendString(command, null, 0, 0);
command = "play MyMp3";
mciSendString(command, null, 0, 0);
}
// Fast Forward
// needs a better skip Implementation
public void FFW()
{
if (isPlaying == true)
{
string command = "set MyMp3 time format ms";
mciSendString(command, null, 0, 0);
command = "seek MyMp3 to " + (elapsedTime.ToString() + ffw5sec.ToString());
mciSendString(command, null, 0, 0);
command = "play MyMp3";
mciSendString(command, null, 0, 0);
//ffw5sec += 5000;
}
}
}
}