Announcement

Collapse
No announcement yet.

PlaySound with resource...

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PlaySound with resource...

    Hello all...

    I have noticed a really wierd problem and i'm not sure if its me or not. I have two wave files in my resource file...

    bounce.rc
    ---------

    BOING WAVE BOING.WAV
    BONK WAVE BONK.WAV


    if I use PlaySound("BOING", hInstance, %SND_RESOURCE) nothing happens but PlaySound("BONK", hInstance, %SND_RESOURCE) does work. I can get the first file "BOING" to play if I modify the resource file like the following...

    bounce.rc
    ---------

    DUMMY WAVE BOING.WAV
    BOING WAVE BOING.WAV
    BONK WAVE BONK.WAV

    I dont understand why putting a dummy resource in first would suddenly make both wave files play properly. Can anybody explain why this would happen?

    Cheers!

    p.s. I should also note that this happens even if I use numbers for the identifiers instead of names..."100/101,BOING/BONK".

    [This message has been edited by mark smit (edited April 23, 2000).]

  • #2
    Not a problem I've heard of before, so we'll have to start at the beginning to track down the cause...

    Is that the complete RC file, or is there other components/data in it?
    How big are the resultant RES/PBR files?
    Which platform did you try this on?
    Did you strip down everything in your code that seems unrelated or did you try writing a small app that does nothing but try to play the wav file?

    It is a curious problem!



    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Lance
    mailto:[email protected]

    Comment


    • #3
      Hello Lance!

      I'm not sure how to post source code in here so I'll just type it in manually. So here it is...

      BOUNCE.RC
      {
      DUMMY WAVE BONK.WAV
      BOING WAVE BOING.WAV
      BONK WAVE BONK.WAV
      }

      BOUNCE.BAS
      {
      #COMPILE EXE
      #INCLUDE "WIN32API.INC"
      #RESOURCE "BOUNCE.PBR"

      function pbmain() as long
      dim hwnd as long

      dialog new %HWND_DESKTOP, _
      "boing", _
      %CW_USEDEFAULT, _
      %CW_USEDEFAULT, _
      256, _
      256, _
      %WS_SYSMENU to hwnd

      dialog show modal hwnd

      call PlaySound("BOING", _
      GetWindowLong(hwnd, %GWL_HINSTANCE), _
      %SND_RESOURCE or %SND_ASYNC)

      end function
      }


      BOING.WAV is 7832 bytes
      BONK.WAV is 2252 bytes
      BOUNCE.RES is 12496 bytes
      BOUNCE.PBR is 12636 bytes
      BOUNCE.EXE is 20992 bytes

      I am running Windows 2000 Pro (2195). The code above is what I have been using to test out wether or not the code really works.
      I did write a small chunk of code to try this out but as it turns out both my original source and the code chunk do the same thing. As of last night the "BONK" wave would play fine but the "BOING" wave would only play once?! (This is also bases on repeated calls to play the wave again)

      Cheers!


      ------------------

      Comment


      • #4
        Things are *very* busy right now, so to save time, can you email these files directly to me and I'll take a look? Thanks!


        ------------------
        Lance
        PowerBASIC Support
        mailto:[email protected][email protected]</A>
        Lance
        mailto:[email protected]

        Comment


        • #5
          Lance that sounds like a software company saying "We're getting ready to release something" *Grin*...

          I don't know if I can help but here's my source that I use when playing from resources, my first guess would be that you are one off on your equates in your .BAS file, from what you are in the .RC file..


          Code:
          '----------------------------------------------------------------------------------------
          Function PlayWavFromResource(hInstance As Long, WaveName As String, WaveType As String)Export As Long
          'Function PlayWavFromResource(hInstance As Long, WaveName As Asciiz, WaveType As Asciiz)Export As Long
          Local hRes As Long
          Local lpWav As Byte Ptr
          Local Wave1 As Asciiz * 10
          Local Wav1 As Asciiz * 10
          Wave1 = WaveName
          Wav1  = WaveType
          hRes = FindResource (hInstance, Wave1, Wav1)
          If hRes Then
              lpWav = LockResource (LoadResource (hInstance, hRes))
              If lpWav Then Function = PlaySound(ByVal lpWav, hInstance, %SND_MEMORY Or %SND_ASYNC)
          End If
          End Function

          ------------------
          Scott
          mailto:[email protected][email protected]</A>
          Scott Turchin
          MCSE, MCP+I
          http://www.tngbbs.com
          ----------------------
          True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

          Comment


          • #6
            I notice you did not interrogate the return from PlaySnd; does it return 'success'?

            Here is the code I use to play sounds from resources (snipped from an application and obviously not complete)..

            Code:
              Stat = PlaySound (BYVAL pResource, hInst, uFlags)
                 ' If a sound was already playing, this returns false but lasterror = %NO_ERROR
            
                 IF ISTRUE(Stat) THEN         ' success on the play
                    INCR J                    ' next time we play the next sound file
                 ELSE                         ' either failed or a sound was already playing
                    LastError = GetLastError
                    IF LastError <>  %NO_ERROR THEN   ' OOPS! Errored out for reason other than a sound already playing!
                      MSGBOX "PlaySoundFailed with error " & STR$(LastError)
                      EXIT DO
                    END IF
                 END IF


            ------------------
            Michael Mattias
            Racine WI USA
            [email protected]
            Michael Mattias
            Tal Systems Inc. (retired)
            Racine WI USA
            [email protected]
            http://www.talsystems.com

            Comment

            Working...
            X