Results 1 to 23 of 23

Thread: How do I add sounds?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2005
    Posts
    16

    Exclamation How do I add sounds?

    ^
    ^
    ^
    ^

  2. #2
    Fanatic Member
    Join Date
    Aug 2005
    Location
    South Africa
    Posts
    760

    Re: How do I add sounds?

    If you want the simplest way to do it, use the 'Playwave' API call, but remember that it is very limited.
    VB Code:
    1. Private Declare Function Playwave Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
    2.  
    3. Private Sub Command1_Click()
    4. Call Playwave(App.Path & "\sound.wav", 1)
    5. End Sub
    Hope this helps!
    If I helped you out, please consider adding to my reputation!

    -- "The faulty interface lies between the chair and the keyboard" --

    VB6 Programs By Me:
    ** Dictionary, Thesaurus & Rhyme-Generator In One ** WMP Recent Files List Editor ** Pretty Impressive Clock ** Extract Firefox History **

  3. #3
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: How do I add sounds?

    Where did you find that? The name doesn't matter when you are calling a .dll, but I've never seen PlayWave. Are you trying to track how many people copy your post?

    VB Code:
    1. Option Explicit
    2.  
    3. Private Const SND_APPLICATION = &H80         ' look for application specific association
    4. Private Const SND_ALIAS = &H10000     ' name is a WIN.INI [sounds] entry
    5. Private Const SND_ALIAS_ID = &H110000    ' name is a WIN.INI [sounds] entry identifier
    6. Private Const SND_ASYNC = &H1         ' play asynchronously
    7. Private Const SND_FILENAME = &H20000     ' name is a file name
    8. Private Const SND_LOOP = &H8         ' loop the sound until next sndPlaySound
    9. Private Const SND_MEMORY = &H4         ' lpszSoundName points to a memory file
    10. Private Const SND_NODEFAULT = &H2         ' silence not default, if sound not found
    11. Private Const SND_NOSTOP = &H10        ' don't stop any currently playing sound
    12. Private Const SND_NOWAIT = &H2000      ' don't wait if the driver is busy
    13. Private Const SND_PURGE = &H40               ' purge non-static events for task
    14. Private Const SND_RESOURCE = &H40004     ' name is a resource name or atom
    15. Private Const SND_SYNC = &H0         ' play synchronously (default)
    16. Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
    17. Dim flag As Boolean
    18.  
    19. Private Sub Command1_Click()
    20. If Not flag Then
    21.   Command1.Caption = "Stop"
    22.   PlaySound "C:\WINDOWS\MEDIA\TADA.WAV", ByVal 0&, SND_ASYNC Or SND_LOOP
    23. Else
    24.   Command1.Caption = "Play"
    25.   PlaySound "C:\WINDOWS\MEDIA\TADA.WAV", ByVal 0&, SND_MEMORY
    26. End If
    27. flag = Not flag
    28. End Sub
    29.  
    30. Private Sub Form_Load()
    31.     'KPD-Team 2000
    32.     'URL: [url]http://www.allapi.net/[/url]
    33.     'E-Mail: [email][email protected][/email]
    34.  Command1.Caption = "Play"
    35. End Sub

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How do I add sounds?

    You can call an API by whatever name you want to as long as you alias it in the declaration. i tought you knew that dglienna.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Dec 2005
    Posts
    16

    Re: How do I add sounds?

    When I try to put that declare function Playsounds thing in the form code, it said I can have only comments after end function. When i put it in a module, when I try to use the function, it can't find it. I'm so confused. Also, I'm trying to use nBass to have my program play mp3 and wma files. I dunno how to get it to play my music. Plz help

  6. #6
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: How do I add sounds?

    Post your code. If you paste my code, and the filenames sync, then it will run without problems.

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Dec 2005
    Posts
    16

    Re: How do I add sounds?

    Ok, now the sound works fine and all. But when the sound plays, I can't move my cursor...

  8. #8
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: How do I add sounds?

    Post your code. I have the code in a button. If you have it in form load, that may throw things off. We need to see what you have tried.

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How do I add sounds?

    You mean the mouse or the cursor like when a textbox has the focus?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Dec 2005
    Posts
    16

    Re: How do I add sounds?

    I'll show you.
    Attached Images Attached Images  

  11. #11
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: How do I add sounds?

    I just added two option buttons, and while the wav was looping, was able to click on both of them. I could also tab between the three controls while it was playing. There must be something in your code.

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Dec 2005
    Posts
    16

    Re: How do I add sounds?

    No way am I gonna use option buttons or command buttons or etc. Yeah, I know you could click on them while the wav is playing but I wanna make this one work...

  13. #13

    Thread Starter
    Junior Member
    Join Date
    Dec 2005
    Posts
    16

    Re: How do I add sounds?

    Here's part of my code:

    Code:
    Private Sub Timer1_Timer()
        If GetAsyncKeyState(vbKeyDown) <> 0 Then
            If Image2.top <> 480 Then
                Image2.top = Image2.top + 48
            Else
                Image2.top = Image2.top - 96
            End If
            PlaySound "C:\WINDOWS\MEDIA\TADA.WAV", 0, SND_SYNC
        ElseIf GetAsyncKeyState(vbKeyUp) <> 0 Then
            If Image2.top <> 384 Then
                Image2.top = Image2.top - 48
            Else
                Image2.top = Image2.top + 96
            End If
            PlaySound "C:\WINDOWS\MEDIA\TADA.WAV", 0, SND_SYNC
        End If
        If GetAsyncKeyState(vbKeyReturn) <> 0 And Image2.top = 480 Then
            RetValue = ChangeRes(1280, 800, 32)
            End
        ElseIf GetAsyncKeyState(vbKeyReturn) <> 0 And Image2.top = 432 Then
            LoadScreen.Show
            Unload TitleScreen
        End If
    End Sub

  14. #14
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: How do I add sounds?

    How often is the timer firing?

  15. #15
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How do I add sounds?

    The timer may be firing too fast causing the thread to peg out the CPU until its done.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  16. #16
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: How do I add sounds?

    You use the SND_SYNC flag in your PlaySound call which means the function doesn't return until the wave file has finished playing, so no other code you use can run. Use the SND_ASYNC flag instead.
    VB Code:
    1. Private Const SND_ASYNC As Long = &H1

  17. #17
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How do I add sounds?

    Good spot Joacim. We all missed that one.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  18. #18

    Thread Starter
    Junior Member
    Join Date
    Dec 2005
    Posts
    16

    Re: How do I add sounds?

    Still doesn't work >.>
    Attached Files Attached Files

  19. #19

    Thread Starter
    Junior Member
    Join Date
    Dec 2005
    Posts
    16

    Re: How do I add sounds?

    Quote Originally Posted by dglienna
    How often is the timer firing?
    The interval is 100

  20. #20
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: How do I add sounds?

    That is 10 times per second. Change it to 1000 (one second) to see if that fixes things. The timer can't reference less than 10ms, and there is no way for the user to click that fast. If that works, you could try 750, or 500.

    It also takes time to move the image. The timer fires again and again, but can't do anything in the time you've given it.

  21. #21
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: How do I add sounds?

    In the project you posted you don't play any sound files. Did you change the call to PlaySound to use the SND_ASYNC flag instead of SND_SYNC? I don't think the Interval of the Timer is especially relevant to this issue.

  22. #22

    Thread Starter
    Junior Member
    Join Date
    Dec 2005
    Posts
    16

    Re: How do I add sounds?

    [QUOTE=Joacim Andersson]Did you change the call to PlaySound to use the SND_ASYNC flag instead of SND_SYNC? QUOTE]

    Yes I did...

  23. #23
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: How do I add sounds?

    Well, not in the project you posted. Can you post the code where you call the PlaySound API function.

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