I am a self-taught VB programmer and have found these forums invaluable. Usually the solution can be found here and I am happy - but this is causing me some trouble...

I want to play a sound, using Media player, twice - one after the other.

I have written a sub that make the sound, and called it 'sound()'

When I put

sound()
sound()

in the code, it only playes once.
If I put an empty for-next loop, it still only plays once, but if I put a msgbox() inbetween them, they both play.

I am sure I am being thick, but any ideas??

Recommended Answers

All 6 Replies

Try to put this code in between

System.Threading.Thread.Sleep(Time)

Code now reads...

 Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Knock()
        System.Threading.Thread.Sleep(1000)
        Knock()

    End Sub

When I click the button, I still only get one click, but after a pause...

What is the code behind Knock()? You could always create a sound file that has the desired sound repeated. Then you would only have to call the routine once as

KnockKnock()

`Private Sub Knock()

    AxWindowsMediaPlayer1.URL = "c:\knock.mp3"
    AxWindowsMediaPlayer1.Ctlcontrols.play()

End Sub`

That is the code for knock()

It may be that your subroutine "Sound()" does not terminate properly, and as a result it does not initialize the second time. check your code in that subroutine

Use this code twice

My.Computer.Audio.Play(audio path, AudioPlayMode.WaitToComplete)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.