5,673,111 members and growing! (21,861 online)
Email Password   helpLost your password?
Languages » VB.NET » General     Intermediate

Play sound in VB.net with

By Hofstetter Daniel

This sample present a simple solution to play sound (mp3, Wav etc..) in a VB.Net (2003) solution.
VB.NET 1.1, Win2K, WinXP, Windows, .NET, WinForms, Visual Studio, VS.NET2003, Dev

Posted: 27 Jan 2006
Updated: 27 Jan 2006
Views: 52,065
Bookmarked: 21 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
7 votes for this Article.
Popularity: 2.54 Rating: 3.00 out of 5
3 votes, 42.9%
1
1 vote, 14.3%
2
0 votes, 0.0%
3
1 vote, 14.3%
4
2 votes, 28.6%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

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

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Hofstetter Daniel


VBA and .net software writer.
For details see my website www.daniel-hofstetter.ch
Occupation: Web Developer
Location: Switzerland Switzerland

Other popular VB.NET articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 5 of 5 (Total in Forum: 5) (Refresh)FirstPrevNext
QuestionStart And End Pointsmemberamiashu6:18 5 Oct '07  
GeneralRe: Play sound in VB.net withmemberZeelia111:59 25 Aug '07  
GeneralGreat helpmemberNasenbaaer8:45 19 Apr '07  
Questionplaylistmemberchse72010:55 4 Mar '07  
GeneralMedia Player with SharpdevelopmemberBThunder19:34 7 Aug '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 27 Jan 2006
Editor:
Copyright 2006 by Hofstetter Daniel
Everything else Copyright © CodeProject, 1999-2008
Web08 | Advertise on the Code Project