私はwinmm.dllを使用してC#でmp3プレーヤーに取り組んでいます
現在、巻き戻し機能に問題があります。
Play 関数の開始時にタイマーを開始します。
FFW 関数を開始するとき、経過時間の現在の値から ffw 5000ms が必要です。
たとえば、曲の再生を開始して FFW を 6 秒押した場合、再生は 6000ms + 5000ms(ffw5sec) で続行する必要があります。
しかし、何も起こっていません。今回は何を間違えたのですか?
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;
}
}
}
}