News

Windows Media Player Control In VB.NET (4.0)

0

As a VB.NET programmer, if you need to provide functionality for the user to watch videos in VB.NET application then follow the steps as mentioned below to incorporate this functionality.

Add a new form to your project

Right click on project name in the Solution Explorer, then click on Add, then click on New Item and select Windows Form from the “Add New Item” dialog box.

Add Windows Media Player (WMP) Control

Drag the Windows Media Player control available in the toolbox to the form

Name this Windows Media Player control as mp.

Follow these steps if Windows Media Player control is not available in the toolbox

  • Right click anywhere on the toolbox
  • Click on Choose Items
  • Go to Com Components tab in Choose Toolbox Items dialog box
  • Click on the checkbox of Windows Media Player to add this control to the toolbox

If this option is not available in the Com Components tab of Choose Toolbox Items dialog box then you can add it by clicking on the Browse button. You must browse to wmp.dll which may be available in System32 folder of windows directory.

  • Click Ok. This will add Windows Media Player control to toolbox
  • Resize this control to occupy the form area which must show video to the user
  • Add a new button named “cmdBrowseVideo” to the form, set its text to “Browse Video”
  • Add an OpenFileDialog control to your form and name it as “dialogOpen”
  •  Add the following code to the Click Event of cmdBrowseVideo button.

Add Browse Video button to open a video

Private Sub cmdBrowseVideo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdBrowseVideo.Click

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

mp.URL = dialogOpen.FileName

End If

End Sub

Clicking on cmdBrowseVideo button will open up a File Open dialog box from where you can select a video. This will add selected file path to the URL property of Windows Media Player control. Now you have to control the actions of Windows Media Player in your form.

Add a Play button

Add a new button, name it as cmdPlay and write the following code for its Button Click event

Private Sub cmdPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPlay.Click

mp.Ctlcontrols.play()

End Sub

Add Stop button

Add a new button, name it as cmdStop and write the following code for its Button Click event

Private Sub cmdStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStop.Click

mp.Ctlcontrols.stop()

End Sub

Add Pause button

Add a new button, name it as cmdPause and write the following code for its Button Click event

Private Sub cmdPause_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPause.Click

mp.Ctlcontrols.pause()

End Sub

Form Load Function

Add the following code to form load if you are passing file path from some previous screen and assigning it to a variable CurrentPath

Private Sub frmVideos_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

mp.URL = CurrentPath

mp.Ctlcontrols.play()

End Sub

This short tutorial has elaborated all the steps required to enrich a VB.NET form with multimedia functionality. You can utilize this information to develop even much more sophisticated multimedia functionality to your application.

Featured images:
  •  License: Royalty Free or iStock source: http://i50.tinypic.com/qnwck6.jpg
  •  License: Royalty Free or iStock source: http://i50.tinypic.com/4j7tk.jpg
  •  License: Royalty Free or iStock source: http://i45.tinypic.com/19xaid.jpg

Learn more about VB.NET, click here.

Java Program To Calculate Lines Of Code

Previous article

Cooking Meets Technology: 3 Ways To Take Your Cooking Passion Online

Next article

You may also like

Comments

Comments are closed.

More in News