Media Player  - Visual Basic 2008

Ngày đăng: 16:16:41 08-07-2012

Media Player  - Visual Basic 2008

This tutorial will show you how to make media player program in visual basic 2008.

Open Visual Basic 2008 Express Edition. (If you don't have the program click here to download it for free.)

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, 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 it's text property to "Song":

Add OpenFileDialog to the form:

Right click on OpenFileDialog1 in the gray area and click on properties. Change it's Filter property to Music File|*.mp3

Double click on the button "Song" and add the following highlighted code:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesButton1.Click

OpenFileDialog1.ShowDialog()

AxWindowsMediaPlayer1.URL = OpenFileDialog1.FileName

End Sub

When you play the program, click on Song button and that should show you a Open File Dialog to choose a song. Make sure that the song is in mp3 format.