SolvedLooping A Sound

Posts 1–11 of 11 · Page 1 of 1
Looping A Sound
heiii guys i dont know why my code is not doing what is suposed to do maybe im not doing it the right way

here there code:
Code:
 
        If sec = 0 And min = 0 And hour = 0 Then
            For i As Byte = 1 To 3
                My.Computer.Audio.Play("C:\Windows\Media\tada.wav", AudioPlayMode.Background)
            Next
            tmrstart.Stop()
        End If

        If sec = 0 And min > 0 Then
            sec = 60
            min = min - 1
        End If
        If sec = 0 And min = 0 And hour > 0 Then
            sec = 60
            min = 59
            hour = hour - 1
        End If
        If sec > 0 Or min > 0 Or hour > 0 Then
            sec = sec - 1
        End If
these codes are from my countdown timer that im trying to make for me to make it easier for me whiile i play.
the countdown works but i want it that when it finishh counting down it will play a sound 3 times like i put in the looop somehow the loop only play once and stop lol

so finally my question, HOW do i make it play 3 times?
Quote Originally Posted by franzyx View Post
heiii guys i dont know why my code is not doing what is suposed to do maybe im not doing it the right way

here there code:
Code:
 
        If sec = 0 And min = 0 And hour = 0 Then
            For i As Byte = 1 To 3
                My.Computer.Audio.Play("C:\Windows\Media\tada.wav", AudioPlayMode.Background)
            Next
            tmrstart.Stop()
        End If

        If sec = 0 And min > 0 Then
            sec = 60
            min = min - 1
        End If
        If sec = 0 And min = 0 And hour > 0 Then
            sec = 60
            min = 59
            hour = hour - 1
        End If
        If sec > 0 Or min > 0 Or hour > 0 Then
            sec = sec - 1
        End If
these codes are from my countdown timer that im trying to make for me to make it easier for me whiile i play.
the countdown works but i want it that when it finishh counting down it will play a sound 3 times like i put in the looop somehow the loop only play once and stop lol

so finally my question, HOW do i make it play 3 times?
I assume Audio.Play is an asynchronous operation. That means that it won't wait til the sound finishes playing before it jumps to the next cycle of the loop. Really you're just trying to play 3 sounds all at the same time and only 1 is actually being played properly. Add a Threading.Thread.Sleep() after the call to "Play" to wait until the sound finishes and then play it again.
ahh fml now im getting this error while debug attempt:


Error 1 The "GenerateResource" task failed unexpectedly.
System.DllNotFoundException: Unable to load DLL 'FileTracker.dll': A dynamic link library (DLL) initialization routine failed. (Exception from HRESULT: 0x8007045A)
at Microsoft.Build.Shared.NativeMethodsShared.InprocT racking.StartTrackingContextWithRoot(String intermediateDirectory, String taskName, String rootMarker)
at Microsoft.Build.Utilities.FileTracker.StartTrackin gContextWithRoot(String intermediateDirectory, String taskName, String rootMarkerResponseFile)
at Microsoft.Build.Tasks.GenerateResource.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsof t.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstant iatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask, Boolean& taskResult) CountDown

have happened several times to me but it goes always after closing and reopening the visual studio.
have this have happen to you?
@franzyx
Loop Issue:

Typically, Thread.Threading.Sleep() is a bad idea, there really is very little real application uses for it (there are some, but not often) However I wrote a quick function to make your life easy. Works fine.

Code:
Public Function PlaySound(ByVal amount As Integer)
        For i As Integer = 1 To amount
            My.Computer.Audio.Play("C:\Windows\Media\tada.wav", AudioPlayMode.Background)
            'This will sleep the thread for 700ms which is just about exactly enough time for the sound to play
            Threading.Thread.Sleep(700)
            'This will allow other application actions to continue, otherwise your application will "lock" entirely, it's the next best thing to multithreading.
            Application.DoEvents()
        Next i
    End Function
To use it, simple place this anywhere you need it.
Code:
Playsound(3)

This Function will allow you to play any sound in any folder

Code:
Public Function PlaySound(ByVal Amount As Integer, ByRef SoundDirectory As String)
        For i As Integer = 1 To Amount
            'My.Computer.Audio.Play("C:\Windows\Media\tada.wav", AudioPlayMode.Background)
            My.Computer.Audio.Play(SoundDirectory)
            'This will sleep the thread for 700ms which is just about exactly enough time for the sound to play
            Threading.Thread.Sleep(700)
            'This will allow other application actions to continue, otherwise your application will "lock" entirely, it's the next best thing to multithreading.
            Application.DoEvents()
        Next i
    End Function

To use

Code:
PlaySound(3,C:\Windows\Media\tada.wav)



There is no reason to place this in a timer. Infact if you have to place it in a timer, it may (on occasion) cause issues, because it could trigger the function X amount of milliseconds. It's a "Dirty Method" but works for what it's needed for.

Errors:

There could be a few reasons why, not really a Big Deal, MSDN has an article , I experieced it before as well when I had 2010 Express / PRO installed and VS11 Pro & Ultimate Beta Installed.

Supposidly it could be a conflict between Framework 4.5 Beta / Or one of the other beta // prereleases

There is a workaround here https://connect.microsoft.com/Visual...ult-0x8007007e

If that doesn't help, read the blog here, there is another fix as well The "GenerateResource" Task Failed Unexpectedly : Unable to load FileTracker.dll - Developer Support Languages - VC++, C# and VB.NET - Site Home - MSDN Blogs

Seems like a very common issue.
thankz @Jason and @NextGen1 for your help. worked the way i wanted it
Marked solved. GJ Jason and NG.
PS: Nextgen has way too much time in his hands.
Quote Originally Posted by Hassan View Post
Marked solved. GJ Jason and NG.
PS: Nextgen has way too much time in his hands.
I don't know about you, but a basic function shouldn't take more then 40 seconds to construct.
Quote Originally Posted by NextGen1 View Post


I don't know about you, but a basic function shouldn't take more then 40 seconds to construct.
I was talking about the rest of the post :P
was thinking of this just yesterday...
Posts 1–11 of 11 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us