Win32Lib: playing .wav usurps normal program flow?
- Posted by Dan Moyer <DanMoyer at PRODIGY.NET> Oct 28, 1999
- 586 views
David, I have three problems finishing my first Euphoria windows program (first two problems previously mentioned here earlier): 1. MODAL WINDOWS : if open modal, then minimize it, then REOPEN (not restore) it, close it, & click anywhere in main, HANGS UP; 2. SETTEXT IN A LABEL: if I concatenate quoted "text" & a sequence variable it puts BOTH in label, but if I concatenate sequence variable & quoted "text", it only puts sequence variable there; 3. PLAYING WAVE FILE USURPS "setVisible" in program flow: I added some sound to a program, & "setVisible" seems to be relating weirdly with the sound playing; my program flow first sets some controls visible, & then plays a .wav file, but what actually happens is that the sound plays first, & then the controls become visible when the sound is finished playing. This results in a very dorky look, because significant expanses of the screen disappear for an unpalatable length of time (while the .wav is playing), before something finally shows back there. I hope there's some way to make this not work like this? In case the specific method I chose to use to play the wave file is responsible, & someone could suggest a better way, here's what I did, lifted from Hecnor's multiplication exercise in the archive: -- TO PLAY A .WAV FILE: procedure playsound(sequence wave) atom file file = allocate_string(wave) c_proc(xPlaySound, {file, 1, 0}) free(file) end procedure In case there isn't a better way to play a wave, here's a demo I made of the problem (using your IDE, which works real nice!): (NOTE THAT YOU HAVE TO NAME SOME (short) .WAV FILE TO 'test.wav' FIRST) -- demo of problem with .wav sound happening before setVisible, -- even though setVisible is commanded before playsound. include Win32Lib.ew without warning global constant 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 ) --------------------------------------- -- TO PLAY A .WAV FILE: procedure playsound(sequence wave) atom file file = allocate_string(wave) c_proc(xPlaySound, {file, 1, 0}) free(file) end procedure ------------------------------------ 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) setText(LText2,"This text should have shown BEFORE anything was spoken!") setVisible(LText2,False) end procedure onOpen[TheWindow] = routine_id("TheWindow_onOpen") ----------------------------------- --DO THE TEST: procedure DoTest_onClick () setVisible(LText2,True)-- TEXT should become VISIBLE; playsound("test.wav") -- THEN sound should happen. 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 ) Hope you can help, Dan Moyer