System.Media.SoundPlayer help

pritam6012

New member
Joined
Jul 9, 2012
Messages
1
Programming Experience
Beginner
I am trying to play multiple sounds in vb.net, but unable to play. Only the last file is played. i.e. "2.wav"
When debugged, both "1.wav" & "2.wav" is playing. But in normal mode, only the last file is played.

I wrote the following code.

VB.NET:
Public Class Form1
    Dim sound As New System.Media.SoundPlayer


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


        sound.SoundLocation = "C:\sound\1.wav"
        sound.Play()


        sound.SoundLocation = "C:\sound\2.wav"
        sound.Play()




    End Sub
End Class
 
The System.Media.Soundplayer class uses the Playsound API, which unfortunately does not allow playing multiple files simultaneously, even in different instances. Use the Windows Media Player object instead, use a different instance for each sound to be played. You can also use the mciSendString API instead, but it is slightly more complicated. Using different aliases for each open commands will play them simultaneously.

This is also more easily achievable through the DirectX SDK's DirectSound API. Or XNA.
 
Back
Top