Results 1 to 10 of 10

Thread: [RESOLVED] Wav file from resource file problem

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Resolved [RESOLVED] Wav file from resource file problem

    I have added a wav file to a resource file, its in a folder called WAVE and it has an id of 101.

    When I click on the command button, it does not play the sound, instead it plays a beep.

    This is what I have:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Const SND_ASYNC = &H1
    4. Private Const SND_FILENAME = &H20000
    5.  
    6. Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, _
    7.                                                                        ByVal hModule As Long, _
    8.                                                                        ByVal dwFlags As Long) As Long
    9.  
    10. Public Sub ButtonClickSound(cb As CommandButton)
    11.     With cb
    12.         PlaySound LoadResData(101, "WAVE"), ByVal 0&, SND_FILENAME Or SND_ASYNC
    13.     End With
    14. End Sub
    I am then calling it in the click event of the command button like so:
    VB Code:
    1. ButtonClickSound Command1

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: Wav file from resource file problem

    I even took out the reference to the command button name and I get the same result.

  3. #3
    Lively Member
    Join Date
    Apr 2004
    Posts
    113

    Re: Wav file from resource file problem

    The wave will play only after you have compiled your application and run your executable. Unfourtanetly you cannot hear the wave while designing.

    Compile your application and run it and your should be able to hear the wave file.

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: Wav file from resource file problem

    Quote Originally Posted by rami.haddad
    The wave will play only after you have compiled your application and run your executable. Unfourtanetly you cannot hear the wave while designing.

    Compile your application and run it and your should be able to hear the wave file.
    already tried that and hear the same sound in the IDE as well as when compiled.

  5. #5
    Lively Member
    Join Date
    Apr 2004
    Posts
    113

    Re: Wav file from resource file problem

    Try calling the wave file like this (must be compiled):

    VB Code:
    1. PlaySound("101", App.hInstance, SND_RESOURCE Or SND_NOWAIT Or SND_NODEFAULT Or SND_ASYNC)

    The SND_RESOURCE variable tells the PlaySound function that your wave is located in the ressource file.

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: Wav file from resource file problem

    Quote Originally Posted by rami.haddad
    Try calling the wave file like this (must be compiled):

    VB Code:
    1. PlaySound("101", App.hInstance, SND_RESOURCE Or SND_NOWAIT Or SND_NODEFAULT Or SND_ASYNC)

    The SND_RESOURCE variable tells the PlaySound function that your wave is located in the ressource file.
    before i can use that, i am going to need the constants for SND_RESOURCE Or SND_NOWAIT Or SND_NODEFAULT

    Private Const SND_RESOURCE = &H40004
    Private Const SND_NOWAIT = &H2000
    Private Const SND_NODEFAULT = &H2
    Private Const SND_ASYNC = &H1
    expected =
    VB Code:
    1. PlaySound("101", App.hInstance, SND_RESOURCE Or SND_NOWAIT Or SND_NODEFAULT Or SND_ASYNC)

  7. #7
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: Wav file from resource file problem

    Give this a try, it works for me in the IDE and as a compiled exe...
    VB Code:
    1. Option Explicit
    2.  
    3. Private Const SND_ASYNC = &H1
    4. Private Const SND_MEMORY = &H4
    5.  
    6. Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, _
    7.                                                                        ByVal hModule As Long, _
    8.                                                                        ByVal dwFlags As Long) As Long
    9.  
    10. Private Sub Command1_Click()
    11.    
    12.     PlaySound StrConv(LoadResData(101, "CUSTOM"), vbUnicode), ByVal 0&, SND_MEMORY Or SND_ASYNC
    13.    
    14. End Sub
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  8. #8
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    UK
    Posts
    417

    Re: Wav file from resource file problem

    I needed to do the same thing only a few weeks back the way I found is as someone already said above that it only works when compiled. but You can also play the data with Waveout API calls, but you will need to extract the wave data from the resource and add the wave header info, then you can then use the Waveout api calls, for more info on the wav file the link below it was written for C++ but is easy to understand and convert to VB

    http://www.borg.com/~jglatt/tech/wave.htm

    hope it may help.
    When your dreams come true.
    On error resume pulling hair out.

  9. #9
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: Wav file from resource file problem

    The code I posted above (#7) works just fine in the IDE.
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: Wav file from resource file problem

    yep, works perfectly. thanks pnish!!

    Quote Originally Posted by pnish
    Give this a try, it works for me in the IDE and as a compiled exe...
    VB Code:
    1. Option Explicit
    2.  
    3. Private Const SND_ASYNC = &H1
    4. Private Const SND_MEMORY = &H4
    5.  
    6. Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, _
    7.                                                                        ByVal hModule As Long, _
    8.                                                                        ByVal dwFlags As Long) As Long
    9.  
    10. Private Sub Command1_Click()
    11.    
    12.     PlaySound StrConv(LoadResData(101, "CUSTOM"), vbUnicode), ByVal 0&, SND_MEMORY Or SND_ASYNC
    13.    
    14. End Sub

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