Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitlePlay an audio file with the Media Player control in VB .NET
DescriptionThis example shows how to play an audio file with the Media Player control in VB .NET.
Keywordsaudio, Media Player, Media Player control, VB .NET, multimedia
CategoriesMultimedia, VB.NET
 
First, open the Toolbox, right-click, and select Add/Remove Items. Select the Windows Media Player control located at Msdxm.ocx.

Add a Windows Media Player control to the form. This example makes the control invisible and then controls it with code.

When the user clicks the Play button, the program disables the button. It sets the Media Player control's FileName property to the name of the file to play and then calls its Play method.

When the control finishes playing the file, it raises its EndOfStream event and hte program re-enables the Play button.

 
Private Sub btnPlay_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles btnPlay.Click
    btnPlay.Enabled = False
    Application.DoEvents()

    Dim file_name As String = Application.StartupPath
    file_name = file_name.Substring(0, file_name.Length - 3)
    AxMediaPlayer1.AutoStart = False
    AxMediaPlayer1.FileName = file_name & "Test.wav"
    AxMediaPlayer1.Play()
End Sub

Private Sub AxMediaPlayer1_EndOfStream(ByVal sender As _
    Object, ByVal e As _
    AxMediaPlayer._MediaPlayerEvents_EndOfStreamEvent) _
    Handles AxMediaPlayer1.EndOfStream
    btnPlay.Enabled = True
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated