Public Class Sound
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click ' Play Dim ofd As New OpenFileDialog ofd.Filter = "MP3 files|*.mp3|WAVE files|*.wav|Windows Media Audio files|*.wma" Dim filename As String = "" Try ofd.ShowDialog() filename = ofd.FileName 'To play.>> Select Case filename.Substring(filename.Length - 3, 3).ToUpper 'Play MP3 files with the default player.>> Case "MP3" My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Question) Process.Start(filename) 'Play WAV files with the default player.>> Case "WAV" My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Question) My.Computer.Audio.Play(filename) 'Play WMA files with the default player.>> Case "WMA" Process.Start(filename) End Select Catch ex As Exception MessageBox.Show(ex.ToString) End Try End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'To stop playing.>> My.Computer.Audio.Stop() End End Sub End Class |