How to Play a .wma, .mp3 or other Music
Visual Basic 2008 can load the Windows Media Player library (WMPLib) and play any supported audio file without needing to load the Windows Media Player interface.
Preparation
Add a reference to Windows Media Player wmp.dll
Sample Code
Dim dr As DialogResult
Dim OpenFileDialogMP As New OpenFileDialog
OpenFileDialogMP.Filter = "Windows Media Audio (wma)|*.wma|MPEG3 (mp3)|*.mp3"
dr = OpenFileDialogMP.ShowDialog
If dr <> Windows.Forms.DialogResult.OK Then
Exit Sub
End If
Player.URL = OpenFileDialogMP.FileName
Player.settings.volume = 80
Player.controls.play()
To use the sample code, create a Windows Forms project and paste the code into a Button on the default form, then add this line in the Form Class:
Private Player As New WMPLib.WindowsMediaPlayer
Download Sample Project
Also See
How to Play a .wav Sound or System Sound
How to Host Windows Media Player to Play Music & Video
All code examples on this site have been developed for .Net Framework 3.5 | |||