Skip to main content
Email Password   helpLost your password?

Introduction

A Windows Media Player Control let you play mp3 or wav files with a unique line of vb.net code:

Me.AxWindowsMediaPlayer1.URL = dlgFileDialog.FileName

Step by step explanation

Step 1

Create a new VBA windows application in Visual Studio.

 

Step 2

Add the Media Player control to the toolbox.
Right-click the toolbox and choose Add/Remove Iitems�

Sample screenshot 
 


In the Customize Toolbox chose the COM Components Panel and navigate to Windows Media Player and select it.

Sample screenshot

 

 

Confirm with OK Button.

 

Step 3

Add the control to the Main form.
Select the Windows Media Player in the toolbox and ad it to the main form.


Sample screenshot 


 
Step 4

Change the Visible property of the control to false.


 Sample screenshot

 
Step 5

Add a Button control to the main form.

Sample screenshot
 

Step 6


Double-click the Button and add the following code to the Click-event procedure.

Private Sub Button1_Click(ByVal sender As System.Object, _
                          ByVal e As System.EventArgs) _
                          Handles Button1.Click 
        Const DATA_FILE_EXTENSION As String = ".mp3"
        Dim dlgFileDialog As New OpenFileDialog 
            With dlgFileDialog
            .Filter = DATA_FILE_EXTENSION & _
            " files (*" & DATA_FILE_EXTENSION & "|*" & DATA_FILE_EXTENSION 
            .FilterIndex = 1
            .RestoreDirectory = True 
            If .ShowDialog() = DialogResult.OK Then 
                'Play the sound file
             Me.AxWindowsMediaPlayer1.URL = dlgFileDialog.FileName 
            End If 
        End With 
End Sub

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralSHort way exist and i will show you Pin
ekeolere olaide
14:50 30 Oct '09  
QuestionStart And End Points Pin
amiashu
6:18 5 Oct '07  
GeneralRe: Play sound in VB.net with Pin
Zeelia11
1:59 25 Aug '07  
GeneralGreat help Pin
Nasenbaaer
8:45 19 Apr '07  
Questionplaylist Pin
chse720
10:55 4 Mar '07  
GeneralMedia Player with Sharpdevelop Pin
BThunder
19:34 7 Aug '06  


Last Updated 27 Jan 2006 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2009