Click here to Skip to main content
Click here to Skip to main content
Go to top

WMP Power Hour APP

, 31 Jul 2007
Rate this:
Please Sign up or sign in to vote.
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. Smile | :)

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

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

You may also be interested in...

Comments and Discussions

 
GeneralMy vote of 5 PinmemberHeaven20203-Nov-10 9:38 
GeneralNeat :) Pinmemberlogan13377-Aug-07 13:17 

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

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

| Advertise | Privacy | Mobile
Web01 | 2.8.140926.1 | Last Updated 31 Jul 2007
Article Copyright 2007 by Froz3n
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid