How To Make A MP3 Player In VB.NET

How To Make A MP3 Player In VB.NETSomeone requested me to write a tutorial about making a mp3 player in vb.net by the way i actually don't have time to do it but i am here to do a simple one because i don't want to deny his request or late .. first of all right click on your toolbox and select Choose Items and a window will come up move to COM tab page in that window and search for Windows Media Player when you found it tick it and click ok button .

How To Make A MP3 Player In VB.NET

Then you will see any tool in your toolbox that should be this (Windows Media Player)

How To Make A MP3 Player In VB.NET

Now drag and drop that tool in and go for it's properties and change visible property to false now go ahead and add a listbox , four buttons and a openfiledialog(enable multi select) also make your form look like this .

How To Make A MP3 Player In VB.NET
Change the text property of all buttons as given below

button1 - Play
button2 - Pause
button3 - Stop
button4 - Add

Now double click on button1 and add these codes

        AxWindowsMediaPlayer1.URL = listbox1.SelectedItem

Double click button 2 and add these codes

        AxWindowsMediaPlayer1.Ctlcontrols.pause()

Double click button 3 and add these codes

        AxWindowsMediaPlayer1.Ctlcontrols.stop()

Double click button 4 and add these codes

 openfiledialog1.ShowDialog()
        If Windows.Forms.DialogResult.OK Then
            For Each track As String In openfiledialog1.FileNames
                listbox1.Items.Add(track)
            Next
        End If

Now debug , click add button to add mp3 files to and you know what to do next have fun i am sorry that i couldn't make it advanced i have no time from yesterday .

here is the full source code

Public Class Form1
    Private Sub button1_Click(sender As Object, e As EventArgs) Handles button1.Click
        AxWindowsMediaPlayer1.URL = listbox1.SelectedItem
    End Sub
    Private Sub button2_Click(sender As Object, e As EventArgs) Handles button2.Click
        AxWindowsMediaPlayer1.Ctlcontrols.pause()
    End Sub
    Private Sub button3_Click(sender As Object, e As EventArgs) Handles button3.Click
        AxWindowsMediaPlayer1.Ctlcontrols.stop()
    End Sub

    Private Sub button4_Click(sender As Object, e As EventArgs) Handles button4.Click
        openfiledialog1.ShowDialog()
        If Windows.Forms.DialogResult.OK Then
            For Each track As String In openfiledialog1.FileNames
                listbox1.Items.Add(track)
            Next
        End If
    End Sub
End Class

25 comments

can you post the skin used for the form?

Reply

it's not my form theme , it's my windows theme :)

-Shim

Reply

I'm getting a message that the "extension (.)" of the file is not recognized. The file is the one added to the list. Same message with other files as well.

Reply

What kind of files did you add?

Reply

mp3 files

Reply

Did you check those mp3 files on your default Windows Media Player?

Reply

Yes, the files do play on Media Player.

Reply

And also the same message appears when no files of selected and the Play button is clicked.

Reply

Okay, download this rar and it has the source code for this program https://www.dropbox.com/s/zzxylwj6m0o5wbn/mp3%20src.rar and see whether it works.

Reply

After comparing your code and the code I had worked on, they are exactly the same.

just to be sure, create a project from scratch, only copying and using your code instead. Compiled, same result, same message.

I am running Windows 7 64 bits and using Visual Studio 2010. Wonder if that makes a difference. What was the environment you compiled this under?

Reply

I am running Windows 7 x86(32 bits) and using Visual Studio 2012 by the way maybe there can be any problem in your media player library or the designer of media player.

can you show me a screenshot of the error?

Reply

Yes,but how can I show it? The comments section does not allow that.

Reply

Take a screenshot of the error and upload it to tinypic or some other image hosting website and put the link here to the image.

Reply

Sorry, I've been rather busy, but here is the screenshot of the error.

[url=http://postimg.org/image/6m5uoqb8j/][img]http://s21.postimg.org/6m5uoqb8j/Screen_Shot004.jpg[/img][/url]

Reply

if that does not work try this:

http://postimg.org/image/6m5uoqb8j/

Reply

How can I know the full information about the selected song?
I mean All tags: (Artist, is copyright?, singer, file size, extension, etc...)?
And also I i can change the tags ?

Reply

Hi,
I'm planning on writing a tutorial for that..!

Reply

untill I know we can:
Axwindowmediaplayer as player.

Code.
SongNameLabel.text = player.currentmedia.getfileinfo("Title")
IsCopyrightLabel.text = player.currentmedia.getfileinfo("Copyright")
ArtistNameLabel.text = player.currentmedia.getfileinfo("artist")
durationlabel.text == player.currentmedia.duration.trim()

But how to know how much duration is passed or played?
How to get the image of that MP3 File in picturebox.?
Can we create our own visualation?
I watch one tutorial on codeproject. he used: System.drawlines() or something like this. '( Which draw random lines., But I want to import Bars to my own picturebox.)
I don't want to use the WindowMediaplayer Window

Reply

It's a strange error, I never experienced anything like this. It's better if you ask the experts on forums like Stackoverflow.

Reply

To get the duration use this

Label1.Text = AxWindowsMediaPlayer1.currentMedia.duration - AxWindowsMediaPlayer1.Ctlcontrols.currentPosition


Reply

Hi could you pls help me because I like to diplay the album art of my mp3 when it plays. So i try to put a picture box but i don't know the code how to extract it

Reply

Try this http://glassocean.net/perrys-id3-tag-library/

Reply

Can I ask if you could detect the music's bass in vb.net?

Reply

Hi, would you please be able to tell me the code to make the songs play automatically down the list without clicking on the next song?

Reply

i need a simple music player for my project, canu please help me guys, i need coding for that plz help me out

Reply

Post a Comment

Note: Only a member of this blog may post a comment.