我正在使用 MCI 编写 CD 音频播放器程序,但无法在轨迹栏上显示音频文件的进度。
有谁知道怎么做?
请注意,我必须使用mciSendString
来获取轨道长度。
来自Simple MCI Player - CodeProject,略有改动:
public int GetCurrentPosition()
{
String command = "status MediaFile position";
error = mciSendString(command, returnData,
returnData.Capacity, IntPtr.Zero);
return error == 0 ? int.Parse(returnData.ToString()) : 0;
}
public int GetSongLenght()
{
if (IsPlaying())
{
String command = "status MediaFile length";
error = mciSendString(command, returnData, returnData.Capacity, IntPtr.Zero);
return error == 0 ? int.Parse(returnData.ToString()) : 0;
}
else
return 0;
}
在 VB 中,我在 Timer Tick Sub 中做到了这一点......真的很容易......
rem audio 是 mcisendstring 东西 rem TotalLength 是当前曲目的总秒数
Dim PlayPosition As Long = 0
PlayPosition = audio.SecondsPlayed
If PlayPosition > 0 And PlayPosition < TotalLength Then
TrackBar1.Value = (PlayPosition / TotalLength) * TotalLength
End If