progress bar

I am trying to put a progress bar on a media player

can you help please

Public Sub Readtrack()

ProgressBar1.Minimum = track start()

ProgressBar1.Maximum = track end()

Dim i As Integer

For i = 1 To 100

ProgressBar1.Increment( )

Next i

End Sub




Answer this question

progress bar

  • Jeff Williams

    dont know what I am doing wrong

    this is what I got now and it wont work for me

    Bar1.Minimum = 1

    Bar1.Maximum = 100

    Dim TrackLength As Integer

    Dim TrackPosition As Integer = 1

    Dim TrackPositionPercentage As Integer = 1

    Dim trackPercentageCompleted As Integer = 0

    If TrackLength > 0 Then

    trackPercentageCompleted = TrackPosition \ TrackLength * 100

    End If

    Bar1.Value = trackPercentageCompleted



  • AlucardHellSing

    The mediaplayer should be giving you the media's movielength and current movieposition, so if you want a progressbar to show that, then thinking of the movieposition as a 'percentage completed so far' will avoid you having to mess with the progressbar's min/max settings to show the completionlevel.

    Keep the Progressbar's minimum at 0 and its maximum at 100, and then the progressbarvalue is a percentage from 0-100% completed.

    The code is simply to calculate that 'percentage completed' by dividing the movie's currentposition by the total movielength (which gives a value between 0 and 1 because the currentposition can't go past the movielength), and then *100 to make it a percentage. In the example below, I've replaced the cInt by using a backslash to do the dividing (which gives an integer result anyway):

    Dim MoviePercentageCompleted as integer = 0
    If MovieLength >0 then
         
    MoviePercentageCompleted = MovieCurrentPosition \ MovieLength *100
    End If
    Progressbar1.Value = MoviePercentageCompleted





  • Peter Aspect

    Hi nogchoco

    thanks for the reply

    but I just cant seem to be able to get this to work

    could you possibly elaborate a bit more

    thanks

    cheyenne



  • Andy Britcliffe

    I would keep the progressbar at 0-100 and calculate the track's currentposition as a percentage of the track's length. That would look like this (note that TrackLength must be bigger than 0 to avoid dividing by zero):

    Dim TrackPositionPercentage as integer = 0
    If TrackLength >0 then
         TrackPositionPercentage = cInt(TrackPosition / TrackLength *100)
    End If

    TrackPositionPercentage will then have a value of 0 to 100 which you can simply put into the Progressbar value.


  • stallion_alpa

    Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        Bar1.Minimum = 0
        Bar1.Maximum = 100

        Dim TrackLength As Integer = mediaplayer1.Duration
        Dim
    TrackPosition As Integer = mediaplayer1.CurrentPosition
       Dim
    trackPercentageCompleted As Integer = 0

        If TrackLength > 0 Then
            trackPercentageCompleted = TrackPosition \ TrackLength * 100
        End
    If

        Bar1.Value = trackPercentageCompleted

    End Sub
  • progress bar