Question Sound playback with variables instead of a string errors out

SuperRoach

New member
Joined
Sep 12, 2008
Messages
1
Programming Experience
3-5
Hello there, I am writing a very simple app that grabs a folder and makes a button for each one of them. The user can then click on the button, and have it play a random sound file located inside that one. Very rudimentary, but fun to try out.

VB.NET:
    Public Sub PlayFolderSound(ByVal sender As System.Object, ByVal e As System.EventArgs)
        '        Debug.WriteLine(sender.text)

        '       Debug.WriteLine(baseFolder & "\" & sender.text.ToString & "\" & "mmmorganisedcrime.wav")

        Dim FileList As New Collection
        Dim randObj As New Random
        For Each file As String In My.Computer.FileSystem.GetFiles(baseFolder & "\" & sender.text)
            FileList.Add(file)
        Next
        Dim tmpRandomNumber As Integer = randObj.Next(1, FileList.Count)
        Debug.WriteLine(baseFolder & "\" & sender.text.ToString & "\" & FileList.Item(tmpRandomNumber))

        ' Play the file
        '        My.Computer.Audio.Play(baseFolder & "\" & sender.text.ToString & "\" & "mmmorganisedcrime.wav")
        Try
            My.Computer.Audio.Play(baseFolder & "\" & sender.text.ToString & "\" & FileList.Item(tmpRandomNumber))
        Catch
            Debug.WriteLine("nup")
        End Try
    End Sub

The code dump when trying to run this code, after clicking on a button that has the folder name, which calls this sub is:

VB.NET:
C:\work\Podcast\Sounds\Soundboard\Simpsons\homer-woohoo.wav
A first chance exception of type 'System.NotSupportedException' occurred in mscorlib.dll
nup
The thread 0x1550 has exited with code 0 (0x0).

If I try the line:
VB.NET:
' Lets play the file: C:\work\Podcast\Sounds\Soundboard\Simpsons\homer-woohoo.wav

            My.Computer.Audio.Play(baseFolder & "\" & sender.name & "\homer-woohoo.wav")

Can anyone see what I am doing wrong here? I'm a bit stumped how I get that error, when I can target the file manually and have it play. I guess it appears it won't accept my collection, FileList.item ...
 
Back
Top