C#trackbar mciSendString

时间:2012-10-12 09:05:06

标签: c# mci

我正在使用MCI编写CD音频播放器程序,但我无法在轨迹栏上显示音频文件的进度。

有谁知道怎么做?

请注意,我必须使用mciSendString来获取曲目长度。

2 个答案:

答案 0 :(得分:0)

来自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;
}

答案 1 :(得分: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