Click here to Skip to main content
15,867,488 members
Articles / Desktop Programming / Windows Forms
Article

Another Article on MP3 Players using Windows Media Player

Rate me:
Please Sign up or sign in to vote.
4.21/5 (5 votes)
12 Nov 2008CPOL2 min read 45.5K   1.8K   18   6
Play your MP3s with this Audio Player
Image 1

Introduction

This program was derived from the Ultimate Player Source which can be found on The Code Project. I added a lot of stuff to this MP3 player - current play time and time remaining, re-did the balance track bar (-100, 0, 100) min, value, max properties, respectively, to work correctly.

I do not have any design experience, so don't laugh…chuckles. This does work and is very powerful. Have fun using Audio PlayerWMP. I hate tooltips, so all tips can be found by mousing over the buttons. Tips are loaded in a textbox centered between the two columns of buttons, see picture below:

ap-2.jpg

Selecting MP3s

The Ultimate Player Source only lets you select one file at a time. I thought that opening, selecting 1, opening, selecting 1…(you get the idea) was not exactly what I was looking for, so I added multiselect to the Open File Dialog box.

VB.NET
Private Sub LoadFiles(ByVal mediaType As String)
        Dim supportedFiles As String

        Select Case mediaType
            Case "Audio"
                supportedFiles = audioFiles
            Case Else
                supportedFiles = audioFiles
        End Select

        With ofd
            .InitialDirectory = "C:\Users\" & GetUserName() & "\Music\"
            .Filter = supportedFiles
            .CheckFileExists = True
            .Multiselect = True
            .RestoreDirectory = True
        End With

        If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then

            For Each Me.fileNamePath In ofd.FileNames
                fileNameShow = GetFileName(fileNamePath)
                Me.lstFiles.Items.Add(fileNameShow)
            Next
        End If

    End Sub 

I had to add a GetUserName function (see in the picture above) so everyone could use this program. I got this code from the comments in the program:

VB.NET
Function GetUserName() As String
        If TypeOf My.User.CurrentPrincipal Is  _
        Security.Principal.WindowsPrincipal Then
            Dim parts() As String = Split(My.User.Name, "\")
            Dim username As String = parts(1)
            Return username
        Else
            Return My.User.Name
        End If
    End Function 

Label Timers

Here is the code for the labels that I used in the timerDuration_Scroll Event…

VB.NET
lblTime.Text = axWMP.Ctlcontrols.currentPositionString
lblDuration.Text = Format_
		(Int(axWMP.currentMedia.duration - axWMP.Ctlcontrols.currentPosition)
                              \ 60, "00") & ":" & _
                   Format(Int(axWMP.currentMedia.duration - _
			axWMP.Ctlcontrols.currentPosition)
                               Mod 60, "00").ToString

Volume and Balance Track Bars

I added code to display to the user on how much volume he or she is using, and did the same for the balance (see the above picture).

To the Authors

To all the authors of code that I used (all names are in comments throughout the program), I thank you all very much. Special thanks goes to the creator of Ultimate Player Source for his idea on Windows Media Player.

History

  • 12th November, 2008: Initial post

I have no degree, but I have had programming experience in college (Pascal and COBOL). I worked in construction for 30+ years and now retired. So I decided to take up VB as a hobbyist. I have learned quite a lot by downloading programs from The Code Project. I thank all the authors who have uploaded their articles. This is actually a better place to learn from.

License

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


Written By
Retired
United States United States
I am currently retired.
I have no degree but I have some programming experience
when I was in college(Cobol, Pascal).

My accomplishments thus far are;
Best VB.Net article for January(2009)
Best VB.Net article for July(2009)

Comments and Discussions

 
GeneralMy vote of 5 Pin
Manoj Kumar Choubey24-Feb-12 1:35
professionalManoj Kumar Choubey24-Feb-12 1:35 
GeneralIf you want to try some more .NET Pin
Sacha Barber13-Jul-09 1:48
Sacha Barber13-Jul-09 1:48 
GeneralRe: If you want to try some more .NET Pin
rspercy6513-Jul-09 2:26
rspercy6513-Jul-09 2:26 
Hi Sacha,
Maybe you can help me? On the subject of WMP, I have recently have had a couple
viruss' and had to reformat my harddrives a couple of times now. When I re-install Visual Studio 2008 pro, I cannot load the wmp.dll to the toolbox. It has something todo with the
"RegisterServer.dll did not load" or something like that, but anyway, I have built a new one
using DirectX.AudioVideoPlayback.dll and it works just fine for what i need. A lot of
the media players, to me, are bloated with a lot of stuff that I'll never use. I am retired
and and I guess I am "Old School".

I just took up VB as a hobby and it is like nicotine, very addictive. I'll check your two apps
out and try to see what you have done. I'm not very good with WPF.

THNX 4 Your Advice Sacha, It is well appreciated.
R.S.Percy

rspercy
1 + 1 = 186,440....Depending on the species.

GeneralRe: If you want to try some more .NET Pin
Sacha Barber13-Jul-09 4:55
Sacha Barber13-Jul-09 4:55 
GeneralRe: If you want to try some more .NET Pin
rspercy6513-Jul-09 12:04
rspercy6513-Jul-09 12:04 
GeneralRe: If you want to try some more .NET Pin
Sacha Barber13-Jul-09 21:41
Sacha Barber13-Jul-09 21:41 

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.