Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

WMP Power Hour APP

0.00/5 (No votes)
31 Jul 2007 1  
Using the Windows Media Player Component
Screenshot - PH.jpg

Introduction

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.

Background

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
            Timer1.Stop()
            MessageBox.Show("You did not complete power hour", "Failed")
            Label3.Text = String.Empty
            Label4.Text = String.Empty
        Else
            startTime = DateTime.Now()
            Timer1.Start()
            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
            wmp.Ctlcontrols.next()
            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
        dlg.ShowDialog()
        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 dayk995@cobleskill.edu.

History

  • 31st July, 2007: Initial post

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here