Question:

How do you loop a sound on VB?

by  |  earlier

0 LIKES UnLike

I am making a reminder program that will play a wav file when it is opened (looping). What code do I do to get it to play?

 Tags:

   Report

1 ANSWERS


  1. Here is a link to a small tutorial showing how to play a wav file from VB. The article says that it's for VB.net but it will also work with VB5 and VB6.

    http://www.freevbcode.com/ShowCode.asp?I...

    According to http://www.pinvoke.net, the additional flag which you need to pass to loop the sound is &H8, to stop the sound playing, you simply call the function again passing in a NULL as the filename to play. Also pinvoke.net says that the H20000 flag says that the string passed is a filename, so we need to keep this flag...

    So the code will look something like:

    Private Declare Auto Function PlaySound Lib "winmm.dll" _

        (ByVal lpszSoundName As String, ByVal hModule As Integer, _

         ByVal dwFlags As Integer) As Integer

    Private Const SND_FILENAME As Integer = &H20000

    Private Const SND_LOOP As Integer = &H8

    Public Function LoopWav(ByVal fileFullPath As String) As Boolean

            'return true if successful, false if otherwise

            Dim iRet As Integer = 0

            Try

                iRet = PlaySound(fileFullPath, 0, SND_FILENAME Or SND_LOOP)

            Catch

            End Try



           Return iRet

    End Function

    Public Function EndLoopWav() As Boolean

            'return true if successful, false if otherwise

            Dim iRet As Integer = 0

            Try

                iRet = PlaySound(NULL, 0, 0)

            Catch

            End Try



           Return iRet

    End Function

    I haven't used VB for a while, and haven't actually tested the code above so you may need to do some debugging, but the main thrust of it should be correct :)

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.