Tuesday 12 January 2016

How to make Media Player on vb.net, visual basic 2008 and 2010



This will show you how to make media player program in visual basic 2008.
Open Visual Basic 2008 Express Edition. Click on Project next to Create:




Click on Windows Form Application, and name the project "Media Player" and then click Ok.


You can change the form text to "Media Player". Click on the form and then go to properties window, then change the text property.
The first thing you can do after changing the form text property is adding Windows Media Player to the form. To do that, follow the following steps:
We will add one control that is not included in the toolbox:
On the Toolbox: right click the mouse and click on Choose Items...:





A Window will appear: Click on COM Components.
 

Scroll down to Windows Media Player and check it then click ok.



In the toolbox, scroll down to the new control "Windows Media Player and drag it to the form:


Resize it to fit the form like the picture below and make sure to leave a space between the icon and Windows Media Player:


Change some properties of the Windows Media Player. Right click on it and then click on properties. On the properties window, change the Anchor property to Top, Bottom, Left, and Right.

 


That property will make Windows Media Player stretches to the whole window when the form size maximizes.



Add a button to the form and change its text property to "Song":




Add OpenFileDialog to the form:
Right click on OpenFileDialog1 in the gray area and click on properties. Change its Filter property to Music File|*.mp3
Double click on the button "Song" and add the following code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
OpenFileDialog1.ShowDialog()
AxWindowsMediaPlayer1.URL = OpenFileDialog1.FileName
End Sub
When you play the program, click on Song button and that should show you an Open File Dialog to choose a song. Make sure that the song is in mp3 format.



No comments:

Post a Comment