Windows Media Player

How do I Display the "Status Bar" Info into a textbox?

My form uses the Windows Media Player to Play an .mp3 file. I would like for it to display the Song Length/Time Remaining in a textbox.

To do this i suppose i could use a timer to refresh the Time Remaining part of it.

But i am lost as far as getting the Info in the first place.
kkoserAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
mcriderConnect With a Mentor Commented:
Try this:

Private Sub Form_Load()
    Timer1.Interval = 500
    Timer1.Enabled = False
End Sub
Private Sub MediaPlayer1_PlayStateChange(ByVal OldState As Long, ByVal NewState As Long)
Select Case NewState
    Case 2 ' PLAYING
        Timer1.Enabled = True
    Case 0 'STOPPED
        Timer1.Enabled = False
    Case Else
        Debug.Print NewState
End Select
End Sub
Private Sub Timer1_Timer()
    With MediaPlayer1
        Label1.Caption = CStr(Fix(.CurrentPosition)) & "/" & CStr(Fix(.Duration))
        If .CurrentPosition = .Duration Then Timer1.Enabled = False
    End With
End Sub



Cheers!
0
 
kkoserAuthor Commented:
bumped up the points.
0
 
kkoserAuthor Commented:
Thanx a lot. it works good. But, How do i get it to display the time instead of a count? i.e., a 4:21 minutes long song displays as 261.

0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
mcriderCommented:
if you divide 261 by 60, you get 4.35 minutes... Just takes alittle division and formatting.

Understand?


Cheers!

0
 
kkoserAuthor Commented:
I understand the division part of the issue.


i used this:

 Label1.Caption = CStr(Fix(.CurrentPosition / 60)) & "/" &
                      CStr(Fix(.Duration / 60))

This won't display anything after the whole numbers.( i.e. (4.35) shows as (4)).

Although 261 divided by 60 = 4.35,
the duration for a 4.21 mp3 shows as 261. I wonder why that is?


However, I don't know how to format it to display the same as windows media player.   i.e. 00:00/00:00.

I guess this is what i was looking for.
0
 
mcriderCommented:
In the formula, Fix() returns a whole number.  Remove the Fix() portions and you will get the decimal notation.


Cheers!
0
 
mcriderCommented:
To display a time format, you could use the following function:

Function TimeFormat(lValue As Long) As String
    Dim lMin As Long
    Dim lSec As Long
    lMin = Fix(lValue / 60)
    lSec = lValue - (lMin * 60)
    TimeFormat = Format(lMin, "00:") + Format(lSec, "00")
End Function


Then do:

Label1.Caption = TimeFormat(.CurrentPosition) & "/" & TimeFormat(.Duration)


Cheers!

0
 
kkoserAuthor Commented:
Sorry for not responding so quickly. Kids with the flu...

This works absolutely awesome!

Thanx a lot.

0
 
kkoserAuthor Commented:
One more thing,

I have another question out there (Q.10223451). You had answered it but i had rejected it because i needed more elaboration. Since then, the problem has been resolved and no one has answered it. Could you answer the question so i can "Clean-Up" my mess?

Thanx in advance.

 
0
 
mcriderCommented:
You're quite welcome!  Glad I could help... (I posted on the other question, Waiting for you to grade it...)


Cheers!
0
All Courses

From novice to tech pro — start learning today.