Click here to Skip to main content
16,015,973 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
i want the code for adding sound on button vb.net

i try this but it does not work
My.Computer.Audio.Play(My.Resources.Name, AudioPlayMode.Background)
Posted
Comments
Sergey Alexandrovich Kryukov 1-Mar-12 13:29pm    
Huh?
--SA

Please see this CodeProject article: Play Waves in VB.NET[^].

In particular, the option of playing audio from a resource embedded in the executable (something you are probably trying to do) is explained.

—SA
 
Share this answer
 
v2
Try this

Imports System.Media

Private Sub btnPlay_Click(ByVal sender As Object, ByVal e As EventArgs)
If txtFileNm.Text <> String.Empty Then
Dim wavPlayer As SoundPlayer = New SoundPlayer()
wavPlayer.SoundLocation = txtFileNm.Text
AddHandler wavPlayer.LoadCompleted, AddressOf wavPlayer_LoadCompleted
wavPlayer.LoadAsync()
End If
End Sub

Private Sub wavPlayer_LoadCompleted(ByVal sender As Object, ByVal e As AsyncCompletedEventArgs)
CType(sender, System.Media.SoundPlayer).Play()
End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900