Win32Lib: PlaySound/setVisible solution

new topic     » topic index » view thread      » older message » newer message

You will need to redefine xPlaySound as a function in Win32lib (if you
don't have a registered version of Euphoria, you could just make up your
own name and declare it in your program).

This example is based off of your first example and it's not perfect
(don't click the button multiple times before it's done because you will
get strange results as the 'wavelist' queue "overflows".  Also, on my
system sometimes the first WAV won't play the very first time you click
the button.  I don't know why that is.)  This is just meant as an example
of how you might go about solving your problem.  Sorry, I have no idea why
setVisible behaves as it does and I don't think there's much that can be
done in Win32Lib to solve it (but I'd like to be wrong).

That said, here it is (you'll have to clean up the long lines and provide
samples for 'one.wav', 'two.wav', and 'three.wav'):

--  NOTE: you need to redefine xPlaySound in Win32lib.ew
--  xPlaySound = linkFunc(winmm, "PlaySoundA", {C_POINTER, C_INT, C_INT},
C_SHORT),

include Win32Lib.ew
without warning

constant
SND_NOSTOP = #10,  -- flag used in xPlaySound

TheWindow = create( Window, "Sound/setVisible Problem", 0, 100, 100, 684,
388,0 ),
LText2 = create( LText, "LText2", TheWindow, 132, 96, 444, 76, 0 ),
Restart = create( PushButton, "RESTART", TheWindow, 248, 264, 132, 36, 0
),
DoTest = create( PushButton, "CLICK HERE", TheWindow, 248, 192, 132, 40, 0
),
LText5 = create( LText, "LText5", TheWindow, 136, 8, 408, 80, 0 )

integer wavecount  -- keeps track of which sound is playing
  wavecount = 0

sequence wavelist  -- list of sounds to play
        wavelist = {}

---------------------------------------
-- Prepare to play a series of .WAV files:
procedure playsound(sequence wave)

        -- convert file names to string pointers
--trace(1)
  for i = 1 to length( wave ) do
        wavelist = wavelist & allocate_string( wave[i] )
        end for
--trace(0)

        -- initialize wave count and set timer
        wavecount = 1
        setTimer( TheWindow, 1, 150 )
end procedure

---------------------------------------
procedure TheWindow_onTimer( integer id )

  if id = 1 then

    if wavecount <= length( wavelist ) then
      if c_func(xPlaySound, {wavelist[wavecount], NULL,
                or_all({SND_FILENAME, SND_ASYNC, SND_NOSTOP})}) then
        free( wavelist[wavecount] )
        wavecount += 1
      end if
    else
      wavecount = 0
      wavelist = {}
      killTimer( TheWindow, 1 )
    end if

  end if

end procedure
onTimer[TheWindow] = routine_id( "TheWindow_onTimer" )

------------------------------------
procedure TheWindow_onOpen ()

-- TEST INSTRUCTIONS:
  setText(LText5,"Before you perform this test, name some .wav file
'test.wav' " &
                 "and put it into the programs directory. Click the
button; " &
                 "some text SHOULD show BEFORE test.wav plays; it
doesn't.")

--TEXT TO SHOW WHEN BUTTON CLICKED ; MAKE IT INVISIBLE FOR NOW:
  setFont(LText2,"Arial", 15, Bold)
  setVisible(LText2, False)
  setText(LText2,"This text should have shown BEFORE anything was
spoken!")
end procedure

onOpen[TheWindow] = routine_id("TheWindow_onOpen")
-----------------------------------
--DO THE TEST:
procedure DoTest_onClick ()

  setVisible(LText2, True)-- TEXT should become VISIBLE;
--trace(1)

  playsound({"one.wav","two.wav","three.wav"}) -- THEN sound should
happen.
--trace(0)
end procedure

onClick[DoTest] = routine_id("DoTest_onClick")
------------------------------------
-- RESET TO DO TEST AGAIN:
procedure Restart_onClick ()
  setVisible(LText2, False)
end procedure

onClick[Restart] = routine_id("Restart_onClick")
----------------------------------------------------------------------
WinMain( TheWindow, Normal )

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu