C# trackbar mciSendString

1.5k views Asked by At

I'm writing a CD Audio player program using MCI, but I can't show the progress of the audio file on a trackbar.

Does anyone know how?

Note that I must use mciSendString to get the track length.

2

There are 2 answers

9
CodeCaster On

From Simple MCI Player - CodeProject, slightly altered:

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;
}
0
Bill Gates On

In VB I did this inside a Timer Tick Sub...easy peasy really...

rem audio is the mcisendstring thingy rem TotalLength is total seconds of current track

    Dim PlayPosition As Long = 0

    PlayPosition = audio.SecondsPlayed
    If PlayPosition > 0 And PlayPosition < TotalLength Then
        TrackBar1.Value = (PlayPosition / TotalLength) * TotalLength
    End If