- This topic explains how to create Media Player in VB programming.
- Using this Media Player, you can play audio and video files.
- Tools needed: Button1 (BtnBrowse), OpenFileDialog1 (OpenFileDialog1)
Steps to add Media Player Component to your VB application - Create Media Player in VB
- Step 1: Select Tool Box, and right click anywhere on the tool box and then select Choose option from the popup menu
- Step 2: Select COM Components from the opened frame and choose Windows Media Player from the list and Click OK to go back.
- Step 3: Drag or Select Windows Media Player tool from the toolbox to your VB application.
System.Windows.Forms Namespace – Create Media Player in VB
- The System.Windows.Forms namespace contains classes for creating Windows-based applications.
- It has full advantage of the rich user interface features available in the Microsoft Windows operating system.
IComponentConnector.InitializeComponent Method – Create Media Player in VB
- Help to load the compiled page of a component.
- Syntax
|
1 2 |
'Declaration Sub InitializeComponent |
FileDialog Class – Create Media Player in VB
- FileDialog Class displays a dialog box from which the user can select a file.
Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
- Syntax for FileDialog Class
|
1 2 3 |
'Declaration Public MustInherit Class FileDialog _ Inherits CommonDialog |
FileDialog.Filter Property – Create Media Player in VB
- Gets or sets the current file name filter string, which determines the choices that appear in the “Save as file type” or “Files of type” box in the dialog box.
- Syntax for FileDialog.Filter
|
1 2 |
'Declaration Public Property Filter As String |
Create Media Player in VB – Complete Code
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
Imports System.Windows.Forms Namespace mymediaplayer Public Partial Class Form1 Inherits Form Public Sub New() InitializeComponent() End Sub 'Create a Button name Browse or any name.... 'select Open file dialog from the toolbox..... Private Sub btnBrowse_Click(sender As Object, e As EventArgs) openFileDialog1.Filter = "mp3,wav,mp4,mov,wmv,mpg|*.mp3;*.wav; *.mp4;*.mov;*.wmv;*.mpg|all files|*.*" If openFileDialog1.ShowDialog() = DialogResult.OK Then ‘helps to load media file in media player axWindowsMediaPlayer1.URL = openFileDialog1.FileName End If End Sub End Class End Namespace |
Create Media Player in VB
If you have any suggestions, please contact us…









