This is supposed to play a click sound. It usually does, but it frequently plays a PFFFFFFT instead!mediaSoundPlayer.Stream =
My.Resources.PodVwBymediaSoundPlayer.Load()
mediaSoundPlayer.Play()
I have other sounds in the program, and, they misfire occasionally, too!

mediaSoundPlayer.Play() does not always play right!
Page123
The built in help suggests something similar to this:
Public
Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickMediaSoundPlayer.Stream =
My.Resources.dizzymisMediaSoundPlayer.Load()
End Sub Sub Player_LoadCompleted( _ ByVal sender As Object, _ ByVal e As _System.ComponentModel.AsyncCompletedEventArgs) _
Handles MediaSoundPlayer.LoadCompleted If Me.MediaSoundPlayer.IsLoadCompleted Then Me.MediaSoundPlayer.Play() End If End SubEnd
ClassOr help using a different approach:
Sub PlaySoundFromResource()
Dim sndPing as new SoundPlayer(SoundRes.GetType(), "Ping.wav")
sndPing.Play()
End Sub
Or if you see my earlier post to you last question, you may need to save the System.IO.MemoryStream to variables which MAY load the sound faster. I have no idea on which memory management technique might work best.
vanRepin
I would think that playing a click sound when a key is pressed would be a very common thing! Why is this so difficult Half of the time I get a PFFFFFFFFT instead of a click!
Dim
clickerx = My.Resources.clickerxPlaySound(clickerx)
Private
Sub PlaySound(ByVal work)mediaSoundPlayer.Stream = work
mediaSoundPlayer.Load()
Do Until Me.mediaSoundPlayer.IsLoadCompleted
Loop
Me.mediaSoundPlayer.Play()
End Sub
NoteMe
Assigning a diifferent player for each sound may help, as well as loading the streams during the form load. The following seems to work well except that if someone repeatedly clicks like mad, everything else will come to a stop until every pending sound has been played.
The smaller the WAV file, the better the preceived 1 for 1 response is.
(Tested with some XP system sounds imported to be resources, and renamed.)
In form1.designer.vb
...
Friend WithEvents Button1 As System.Windows.Forms.Button Private WithEvents Player As New Media.SoundPlayer Private WithEvents Player2 As New Media.SoundPlayer Friend WithEvents Button2 As System.Windows.Forms.ButtonIn form1.vb
Imports
System.MediaPublic
Class Form1 Function GetSound(ByVal resname As String) As System.IO.MemoryStream Dim obj As Object = My.Resources.ResourceManager.GetObject(resname) Dim b As System.IO.MemoryStream = obj Return b End Function Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickPlayer.PlaySync()
End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.ClickPlayer2.PlaySync()
End Sub Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LoadPlayer.Stream = GetSound(
"d1")Player2.Stream = GetSound(
"d2") End Sub Private Sub Button1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseUp ' these STOP statements did not seem to have any effect My.Computer.Audio.Stop()Player.Stop()
End Sub Private Sub Button2_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button2.MouseUp ' these STOP statements did not seem to have any effect My.Computer.Audio.Stop()Player2.Stop()
End SubEnd
Class