Make a media player in vb.net


Premium (Not Free) Video Tutorials

Free Video Tutorials & Free Tools


You'll want to start by creating a new VB Windows Forms Application.

Once you do, and you have the default form layout, go ahead an start customizing your form. What I did was I dragged out 2 Picture Boxes, and a Menu Strip. For the picture boxes, its pretty easy.

Just find a picture on Google Images for something that resembles Music and one that resembles Video, then set that as the picture in the picture box.

Here is what my setup turned out to be. 1 Now double click the picture box for video to go in the code.

 Here's the code for it, so that you can open a file.

Dim o As New OpenFileDialog

o.RestoreDirectory = True

o.Filter = "AVI Videos (*.avi)|*.avi|WMV Videos (*.wmv)|*.wmv|MOV Videos (*.mov)|*.mov|MP4 Videos (*.mp4)|*.mp4"

o.FilterIndex = 1

o.FileName = ""

o.ShowDialog()

Okay, also, before you can continue, go to "Project">"Add Windows Form…" and add a user form called Form2, or you can name it whatever, but for this, we're using Form2. Go to your toolbox, right click it, and go to "Add Items…". Then when it comes up click "COM Components" and scroll down until you see "Windows Media Player".

Click the checkbox next to it, click Apply, then Okay. Now, customize your form2, and also change the Dock on your WMP Item to "Fill". Now add this to your code for the picture box:

Form2.AxWindowsMediaPlayer1.URL = o.FileName

Form2.Show()

Now, copy all the code. Double click the other picture box, and paste the code there. We need to change things though.

You need to change this:

o.Filter = "AVI Videos (*.avi)|*.avi|WMV Videos (*.wmv)|*.wmv|MOV Videos (*.mov)|*.mov|MP4 Videos (*.mp4)|*.mp4" to this:

o.Filter = "MP3 Files (*mp3)|*.mp3|WAV Files (*.wav)|*.wav|WMA Files (*.wma)|*.wma"

That should do it for that code.

Now on your Menu Strip, you saw how mine said "Video Playback…". Put something like that in yours. Now click it once to get the drop down and add the following: "Video Controls" and "No Border" Single click the "Video Controls" to get the flyout menu. Add "No Controls", "Mini Mode", and "Full Mode" Lets start with coding the No Border Item. Double click it to get the code. Its really simple, just add the following.

 

If NoBorderToolStripMenuItem.Checked = False Then Form2.FormBorderStyle = Windows.Forms.FormBorderStyle.None NoBorderToolStripMenuItem.Checked = True Else Form2.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable NoBorderToolStripMenuItem.Checked = False

End

If It checks to see if the menu item is checked, if it isn't it'll set form2 to no border, if it is, it'll set it to sizable. Now, for setting the video controls, double click on No Controls to start with. The code for this is:

Form2.AxWindowsMediaPlayer1.uiMode = "none" Now for Mini Mode, its this:

Form2.AxWindowsMediaPlayer1.uiMode = "mini" Catching on? Here's full mode.

Form2.AxWindowsMediaPlayer1.uiMode = "full"

That's about it! If you wanna take it a step further, read everything inside of the spoiler for taking it a step further. If you don't skip ahead of the spoiler to know how to distribute this. Taking it a step further. That just means to be able to click on the video to pause it. So go to the form that has the WMP Object. Now douuble click it. Now on the drop down menu that has the "Enter" Here: Okay, now. Change it to ClickEvent. Now at the top you'll want to do "Imports AxWMPLib" And then in the code, paste the following.

If AxWindowsMediaPlayer1.playState = WMPLib.WMPPlayState.wmppsPlaying Then AxWindowsMediaPlayer1.Ctlcontrols.pause()

Else AxWindowsMediaPlayer1.Ctlcontrols.play() End If

That should do it! Go ahead and try debugging it. If you get any errors, post them down below. I'll try to help. If you want to distribute this program, you'll firstly need to save it and then go to "Build">"Build (Name of project)". Then go to where your files were saved. In my case the path is C:\Users\Nick\Documents\Visual Studio 2010\Projects\MediaPlayer\. No go into the folder that is named the same. So in my case, I'd be in C:\Users\Nick\Documents\Visual Studio 2010\Projects\Media Player\Media Player\ Now, go into the bin folder, then Release. The folder you should be in, in my case atleast, is C:\Users\Nick\Documents\Visual Studio 2010\Projects\Media Player\Media Player\bin\Release Now, Just copy the executable and the two DLLs to your desktop. Package them into a ZIP file, include a readme.txt if you wish and then send it to whoever you want.

Thanks to Mewkid999 for this excellent tutorial!

 

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

Comments

One Response to “Make a media player in vb.net”
  1. Vivian Colaco says:

    i wanted to know how to add a buffer (seek bar) to a media player created in vb.net
    could you please help as soon as possible?

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!

Powered by WP Hashcash

This blog uses the cross-linker plugin developed by Web-Developers.Net