Click here to Skip to main content
15,860,859 members
Articles / Programming Languages / Visual Basic

WMP Power Hour APP

Rate me:
Please Sign up or sign in to vote.
5.00/5 (3 votes)
31 Jul 2007CPOL1 min read 53.4K   1K   18   2
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.

VB.NET
' 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.

VB.NET
'  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.

VB.NET
' 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)


Written By
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
Global Analyser3-Nov-10 9:38 
GeneralNeat :) Pin
chaiguy13377-Aug-07 13:17
chaiguy13377-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.