Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 263,568 times

Contents

Related Categories

Build an MP3 Player - Playing Time

Playing Time

Determining the song's duration

Now that the code has opened the file, we can determine its duration. Whenever a file's open state changes, Media Player triggers an OpenStateChange() event. We'll use this event to calculate the song's duration. Listing D shows this event. As you can see, this event also sets the FileOpen variable.

Listing D: Calculating the duration

Private Sub MediaPlayer1_OpenStateChange(ByVal _
	OldState As Long, ByVal NewState As Long)

Min = MediaPlayer1.Duration * 60
Sec = MediaPlayer1.Duration - (Min * 60)
lblTotalTime = "Total Time: " & Format(Min, "0#") _
	& ":" & Format(Sec, "0#") 'format time to 00:00
    
FileOpen = CBool(NewState)  
End Sub

Keeping track of play time

As one of our final touchups to the application, we can provide the current running time. Earlier, we placed two labels and a timer control on the form for just such a purpose. Listing E contains the code for this feature.

Listing E: Displaying the elapsed time

Private Sub Timer1_Timer()
Min = MediaPlayer1.CurrentPosition * 60
Sec = MediaPlayer1.CurrentPosition - (Min * 60)
If Min > 0 Or Sec > 0 Then
	lblElapsedTime = "Elapsed Time: " & Format(Min, "0#") _
		& ":" & Format(Sec, "0#")
Else
	lblElapsedTime = "Elapsed Time: 00:00"
End If
End Sub 

© 2001 Element K Journals, a division of Element K Press LLC ("Element K"). Element K and the Element K logo are trademarks of Element K LLC

Comments

  • Lyrics support

    Posted by AziMo on 07 Jan 2008

    hey there...does anyone know the way a media player with lyrics support??

     

    thanx!! 

  • Re: TW 2000

    Posted by possible181 on 03 Jun 2007

    Anyone one plz help me with mediaplayer's iserviceprovider and how to program remoting mediaplayer

  • WMP.DLL VB.net media player master

    Posted by Qwazimoto on 08 Nov 2006

    Hi people I have written a few media players and a few turned out good(most were crap thaugh).
    If any one wants any help, Id be glad to.

    My media player im working on now has the followin...

  • Re: [62] Build an MP3 Player

    Posted by KoA on 24 Oct 2006

    Can someone help me?

    First, im getting Object does not support this this methor or property on ".Filename = Filename"
    Next, im getting the same thing for for the 2 options in the timer?
    ...

  • Posted by mazdak_zp on 23 Sep 2005

    when you want to get then path of a FileListBox or DirListBox, if it returns a folder in drive it return for example "c:\windows" without "\" at the end if path. but if the path was a drive it returns...