Results 1 to 5 of 5

Thread: Playing multiple files from array

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2011
    Posts
    6

    Playing multiple files from array

    I'm trying to make a "Simon" game with four buttons labeled 1-4. The game is supposed to read the numbers out loud, but i have a problem with that. I have 4 wav files from google text-to-speech, each named 1-4. I made an number generator that can return like this "42331", and the game is supposed to play 4.wav, 2.wav, 3.wav, 3.wav and 1.wav.
    Here's what i got so far.
    Code:
    Public Class Form1
        Dim rnd As New Random
        Dim i = 0
        Dim level As Integer = 5
        Dim nums As String
        Dim ns
        Dim pla As New System.Media.SoundPlayer
        Function gsa()
            Dim h
            While i < level
                h = Math.Round(rnd.NextDouble * 4)
                If h = 0 Then
                    h = 1
                End If
                nums = nums + h.ToString
                i = i + 1
            End While
            MsgBox(nums)
            Return nums
        End Function
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            ns = gsa()
            i = 0
            While i > level
                pla.SoundLocation = ns(i) + ".wav"
                pla.Play()
                i = i + 1
            End While
        End Sub
    End Class
    It reads nothing.

    If i try with
    Code:
    Imports System.Threading.Thread
    Public Class Form1
        Dim rnd As New Random
        Dim i = 0
        Dim level As Integer = 5
        Dim nums As String
        Dim ns
        Dim pla As New System.Media.SoundPlayer
        Function gsa()
            Dim h
            While i < level
                h = Math.Round(rnd.NextDouble * 4)
                If h = 0 Then
                    h = 1
                End If
                nums = nums + h.ToString
                i = i + 1
            End While
            MsgBox(nums)
            Return nums
        End Function
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            ns = gsa()
            For Each num In ns
                pla.SoundLocation = ns(num) + ".wav"
                pla.Play()
                i = i + 1
            Next
        End Sub
    End Class
    It only plays 1.wav (the last in the sequence)

    I'm new to this forum so please help.

  2. #2

    Thread Starter
    New Member
    Join Date
    Feb 2011
    Posts
    6

    Re: Playing multiple files from array

    bump

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2011
    Posts
    6

    Re: Playing multiple files from array

    bump

  4. #4

    Thread Starter
    New Member
    Join Date
    Feb 2011
    Posts
    6

    Re: Playing multiple files from array

    bump

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: Playing multiple files from array

    try this:

    vb Code:
    1. pla.PlaySync()

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width