Waiting for sound file to finish before playing the next file without freezing the program. VB.NET

43 Views Asked by At

The code I have does what I want it to do however, it freezes the program.

    Dim filePath = "C:\Users\Desktop\Soundfiles\"
    Dim tracks() As String = {Form1.TextBox1.Text, Form1.TextBox2.Text, Form1.TextBox3.Text}

    For i = 0 To tracks.Length - 1
        My.Computer.Audio.Play(filePath + tracks(i) + ".wav", AudioPlayMode.WaitToComplete)
    Next i

So I have tried this code which doesn't freeze the program but only plays the last file in the array.

    Dim Player As WindowsMediaPlayer = New WindowsMediaPlayer
    Dim filePath = "C:\Users\Desktop\Soundfiles\"
    Dim tracks() As String = {Form1.TextBox1.Text, Form1.TextBox2.Text, Form1.TextBox3.Text}

    For i = 0 To tracks.Length - 1

        Player.URL = filePath + tracks(i) + ".wav"
        Player.controls.play()

    Next i

So I am looking for a way of playing the 1st file then wait for it to finish before playing the next file in the array etc. Is there away of doing this? Thank you.

0

There are 0 best solutions below