How to Host Windows Media Player to Play Music & Video
Visual Basic 2008 can host Windows Media Player to play any supported audio or video file.
Preparation
Add Windows Media Player to the Visual Studio Toolbox by right-clicking the Toolbox and selecting Choose Items...:
On the COM (Component Object Model) tab, select wmp.dll and click OK:
Create a small Form with a Button and drag a Windows Media Player control onto the form:
Add the sample code, below, to the Button.
Sample Code
Dim dr As DialogResult
Dim OpenFileDialogMP As New OpenFileDialog
OpenFileDialogMP.Filter = _
"Windows Media Audio (wma)|*.wma|Windows Media Video (wmv)|*.wmv"
dr = OpenFileDialogMP.ShowDialog
If dr <> Windows.Forms.DialogResult.OK Then
Exit Sub
End If
AxWindowsMediaPlayer1.URL = OpenFileDialogMP.FileName
AxWindowsMediaPlayer1.settings.volume = 80
Voila!
Download Sample Project
Also See
How to Play a .wav Sound or System Sound
How to Play a .wma, .mp3 or other Music (No user interface)
All code examples on this site have been developed for .Net Framework 3.5 | |||