Click here to Skip to main content
14,971,215 members
Articles / Programming Languages / Visual Basic
Posted 31 Jul 2007


18 bookmarked

WMP Power Hour APP

Rate me:
Please Sign up or sign in to vote.
5.00/5 (3 votes)
31 Jul 2007CPOL1 min read
Using the Windows Media Player Component
Screenshot - PH.jpg


This is just a fun simple program that I created during some free time at school. This is the first article I've posting, so please bear with me. :)

I've used an article written by Alastair Dallas: Tiny StopWatch Application.

I also used a little tutorial from: Using WMP.


Power Hour is a drinking game that many college students play. The idea is to take a shot of beer every minute for a whole hour. I've imported the Windows Media Player COM so that a song will change every minute.

Using the Code

The first code snippet is the button control click procedure.

' 1) Button Control 

 Dim startTime As DateTime
   Private Sub Button1_Click(ByVal sender As System.Object, _
   ByVal e As System.EventArgs) Handles Button1.Click
       ' If the button is clicked then start the timer.
       ' Once the timer is started and the button is clicked again,
       ' the timer is stopped and the player fails
       If (Timer1.Enabled) Then
           MessageBox.Show("You did not complete power hour", "Failed")
           Label3.Text = String.Empty
           Label4.Text = String.Empty
           startTime = DateTime.Now()
           Button1.Text = "Stop!"
       End If
   End Sub

The second code snippet is the timer control.

'  2) Timer Control 

Private Sub Timer1_Tick(ByVal sender As System.Object, _
	ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim span As TimeSpan = DateTime.Now.Subtract(startTime)
        Label4.Text = span.Seconds.ToString

        ProgressBar1.Value += 1

        If ProgressBar1.Value = 60 Then
            ProgressBar1.Value = 0
            ProgressBar2.Value += 1
            Dim span2 As TimeSpan = DateTime.Now.Subtract(startTime)
            Label3.Text = span2.Minutes.ToString
            If ProgressBar2.Value = 60 Then
                MessageBox.Show("You've completed power hours", _
		"Congratulations!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                ProgressBar2.Value = 0
            End If
        End If
    End Sub

The third code snippet is the menu item to import a playlist.

' 3)  Menu Item to add Play List 

 Private Sub AddMusicToolStripMenuItem_Click(ByVal sender As System.Object, _
	ByVal e As System.EventArgs) Handles AddMusicToolStripMenuItem.Click
        Dim dlg As New OpenFileDialog()
        dlg.InitialDirectory = "C:\"
        dlg.CheckFileExists = True
        dlg.Title = "Import a Playlist from WMP"
        dlg.Filter = "Windows Media Playlists|*.wpl"
        dlg.Multiselect = False
        wmp.URL = dlg.FileName
    End Sub

That's all the code there is for this little project. You need to add the Windows Media Player COM however. To do this, right click on the tool box, select Choose Items.... select COM Components and check Windows Media Player. Now you can add the control to your form.

Points of Interest

The neatest thing about this was the WMP COM. I made it so that people can import their WMP play lists in there and the timer switches the song every minute. This stops people from editing the whole song and cutting it off at a minute like I've seen people do.

If you have any questions, please e-mail me at


  • 31st July, 2007: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Web Developer
United States United States
Still in school, program for fun...

Comments and Discussions

GeneralMy vote of 5 Pin
Global Analyser3-Nov-10 9:38
MemberGlobal Analyser3-Nov-10 9:38 
GeneralNeat :) Pin
chaiguy13377-Aug-07 13:17
Memberchaiguy13377-Aug-07 13:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.