Results 1 to 8 of 8

Thread: PlaySound - how to loop?

  1. #1

    Thread Starter
    Fanatic Member coox's Avatar
    Join Date
    Oct 1999
    Posts
    550

    PlaySound - how to loop?

    Ok, so I'm thick. But how on earth do I get this code to LOOP the sound so it keeps playing? I can't get it to work...
    Code:
    Option Explicit
    
    Private Const SND_APPLICATION = &H80         '  look for application specific association
    Private Const SND_ALIAS = &H10000     '  name is a WIN.INI [sounds] entry
    Private Const SND_ALIAS_ID = &H110000    '  name is a WIN.INI [sounds] entry identifier
    Private Const SND_ASYNC = &H1         '  play asynchronously
    Private Const SND_FILENAME = &H20000     '  name is a file name
    Private Const SND_LOOP = &H8         '  loop the sound until next sndPlaySound
    Private Const SND_MEMORY = &H4         '  lpszSoundName points to a memory file
    Private Const SND_NODEFAULT = &H2         '  silence not default, if sound not found
    Private Const SND_NOSTOP = &H10        '  don't stop any currently playing sound
    Private Const SND_NOWAIT = &H2000      '  don't wait if the driver is busy
    Private Const SND_PURGE = &H40               '  purge non-static events for task
    Private Const SND_RESOURCE = &H40004     '  name is a resource name or atom
    Private Const SND_SYNC = &H0         '  play synchronously (default)
    
    Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" _
    	(ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
    
    Private Sub Command1_Click()
        'KPD-Team 2000
        'URL: http://www.allapi.net/
        'E-Mail: [email protected]
        PlaySound "C:\WINDOWS\MEDIA\TADA.WAV", ByVal 0&, SND_FILENAME Or SND_ASYNC
    End Sub
    Nick Cook
    VB6 (SP6)

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: PlaySound - how to loop?

    Have you tried this?

    VB Code:
    1. PlaySound "C:\WINDOWS\MEDIA\TADA.WAV", ByVal 0&, SND_FILENAME Or SND_ASYNC Or SND_LOOP
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  3. #3

    Thread Starter
    Fanatic Member coox's Avatar
    Join Date
    Oct 1999
    Posts
    550

    Re: PlaySound - how to loop?

    dee-u - thanks very much for replying - appreciate it.

    Yes, I've tried that (and I just copy-pasted your code too) - the sound plays once and that's all. What am I missing...
    Nick Cook
    VB6 (SP6)

  4. #4
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: PlaySound - how to loop?

    How about this? I really can't check it for now...

    VB Code:
    1. PlaySound "C:\WINDOWS\MEDIA\TADA.WAV", ByVal 0&, SND_FILENAME Or SND_LOOP
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  5. #5

    Thread Starter
    Fanatic Member coox's Avatar
    Join Date
    Oct 1999
    Posts
    550

    Re: PlaySound - how to loop?

    Sorry - just plays once again... hmmm.

    And my daughter wanted me to put this picture in for you!

    Nick Cook
    VB6 (SP6)

  6. #6
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: PlaySound - how to loop?

    The PlaySound API only plays one sound at a time and is very limited of its capabilities. You get a lack of control. So if you are making a game or a music app, it is better to use DirectSound or WAVEMIX32, for more control over your sound, and allow more than one sound to play at the same time. Here are some tutorials on DirectSound:

    http://directx4vb.vbgamer.com/DirectX4VB/TUT_DX7_DS.asp
    http://directx4vb.vbgamer.com/DirectX4VB/TUT_DX8_DA.asp

  7. #7

    Thread Starter
    Fanatic Member coox's Avatar
    Join Date
    Oct 1999
    Posts
    550

    Re: PlaySound - how to loop?

    Thanks Jacob - but actually, I sorted it - it was because I was trying to leave out the Private bit in:
    Code:
    Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" _
    	(ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
    No doubt a very basic mistake on my part - but can some kind soul maybe explain why it's so critical?
    Nick Cook
    VB6 (SP6)

  8. #8
    New Member
    Join Date
    Sep 2009
    Posts
    1

    Re: PlaySound - how to loop?

    I tried that code but I get an error message in
    Code:
    Private Declare Function playsound Lib "winmm.dll" Alias "PlaySoundA" _
        (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
    for some reason. It says "Member already exists in a object module from which this object module derives."

    Please help! Here is my code (exactly the same as everybody else has):

    Code:
    Option Explicit
    
    Private Const SND_APPLICATION = &H80         '  look for application specific association
    Private Const SND_ALIAS = &H10000     '  name is a WIN.INI [sounds] entry
    Private Const SND_ALIAS_ID = &H110000    '  name is a WIN.INI [sounds] entry identifier
    Private Const SND_ASYNC = &H1         '  play asynchronously
    Private Const SND_FILENAME = &H20000     '  name is a file name
    Private Const SND_LOOP = &H8         '  loop the sound until next sndPlaySound
    Private Const SND_MEMORY = &H4         '  lpszSoundName points to a memory file
    Private Const SND_NODEFAULT = &H2         '  silence not default, if sound not found
    Private Const SND_NOSTOP = &H10        '  don't stop any currently playing sound
    Private Const SND_NOWAIT = &H2000      '  don't wait if the driver is busy
    Private Const SND_PURGE = &H40               '  purge non-static events for task
    Private Const SND_RESOURCE = &H40004     '  name is a resource name or atom
    Private Const SND_SYNC = &H0         '  play synchronously (default)
    
    Private Declare Function playsound Lib "winmm.dll" Alias "PlaySoundA" _
        (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
    
    Private Sub Command1_Click()
        'KPD-Team 2000
        'URL: http://www.allapi.net/
        'E-Mail: [email protected]
        playsound "C:\Users\Bakke\Desktop\Teit\DrumLoop1.wav", ByVal 0&, SND_FILENAME Or SND_ASYNC
    End Sub
    Please help, I really need it. (I'm getting paid for it)

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