Need some help with audio playback
Hey guys and gals, thanks for taking a look.
Basically my program has a "shuffle" music feature:
vb Code:
For i = 0 To 26
num = randomObject.Next(0, 27)
My.Computer.Audio.Play("C:\Users\Mcturtles\Music\Songs\" & num & ".wav", AudioPlayMode.BackgroundLoop)
Next
Which selects a random number 0 - 26 and selects the corresponding song.
And a straight play feature:
vb Code:
Dim counter As Integer
Do Until counter > 26
My.Computer.Audio.Play("C:\users\mcturtles\music\songs\" & counter & ".wav", AudioPlayMode.WaitToComplete)
counter += 1
Loop
All of these activated by a button(separate for each)
When I click one, it makes the program stop responding. I'm pretty sure it is the .WaitToComplete mode, but I can't find a way to make it continuously play without it. If you can find my error, it would be greatly appreciated.
Also if you could tell me a way to make the shuffle never play the same song twice, that would be awesome as well.
Thanks,
Mcturtles
Re: Need some help with audio playback
Hello Mcturtles,
Welcome to the Forums!!
When you are posting code into the forum, can you please remember to surround it in [code][/code] or [HIGHLIGHT=vb][/highlight] tags? It makes it a lot easier to read. I have done this for you in your above post.
Thanks
Gary
Re: Need some help with audio playback
to play your wavs on a secondary thread (asynchronously) while retaining the WaitToComplete, try this:
vb Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim t As New Threading.Thread(AddressOf playWaves)
t.Start()
End Sub
Private Sub playWaves()
Dim counter As Integer
Do Until counter > 26
My.Computer.Audio.Play("C:\users\mcturtles\music\songs\" & counter & ".wav", AudioPlayMode.WaitToComplete)
counter += 1
Loop
End Sub
End Class