dkl
Full Member
Posts: 234
|
Post by dkl on Nov 13, 2021 19:59:19 GMT -5
I want to display a listbox for 5 seconds and play a sound as it ticks down, but no matter what order I put the code (or mode I choose) the playwave code takes over and won't do anything until the wav file has finished playing eg
unhide listbox for loop timer start playwave (sync, asyn or loop) next or unhide listbox playwave (no mode,,sync, asyn or loop) timer start or unhide listbox start timer for loop playwave (no mode,,sync, asyn or loop) next or unhide listbox for loop playwave (no mode,,sync, asyn or loop) next
etc.......
the playwave code completely takes over and won't even unhide the window until it's finished, even though the code is before the playwave
Any ideas, please? What am I doing wrong?
|
|
|
Post by tsh73 on Nov 14, 2021 2:07:52 GMT -5
This thing cuts playning WAV to 5 sec. Works for me.
t0=time$("ms") timer 5000, [over] playwave "wav8sec.wav", async wait [over] playwave "" t1=time$("ms") print t1-t0
|
|
|
Post by Rod on Nov 14, 2021 3:19:09 GMT -5
Ah, the c in async.
|
|
|
Post by tsh73 on Nov 14, 2021 3:33:48 GMT -5
not tried in LB but in JB ..using wrong word (say asyn) just makes playwave be completely ignored. No sound, no error. My program just reports after 5000 ms.
|
|
|
Post by Rod on Nov 14, 2021 3:44:36 GMT -5
Ok, correct it isn't the c in async, drop it and the whole command is ignored. So something else. Real code would help.
timer 2000,[done]
playwave "beep.wav",asyn wait [done] timer 0 print "done" end
|
|
dkl
Full Member
Posts: 234
|
Post by dkl on Nov 14, 2021 6:22:44 GMT -5
I think I didn't explain myself very well! I don't want a break before the 'wav' file starts. I want it to play as the window open and tick for 5 secs This will play the wav file, which is 1sec long and act as a timer
f$ = "L:\_WAV\1sec_Click.wav" nomainwin WindowWidth = 260 WindowHeight = 100 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2) textbox #1.tb, 10, 10, 200, 30 button #1.1, "ok", [EH],UL, 220, 10, 30, 30 open f$ for Window as #1 #1.tb,"!hide" wait
[EH] '#1.tb,"!show" for a = 1 to 5 playwave f$ next 'wait
[done] #1.tb,"!hide" print "done" wait close #1 end
This will play the wav file, but ignores the code beforehand and only opens the window after, but stays open because of the 'wait' statement
f$ = "L:\_WAV\1sec_Click.wav" nomainwin WindowWidth = 260 WindowHeight = 100 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2) textbox #1.tb, 10, 10, 200, 30 button #1.1, "ok", [EH],UL, 220, 10, 30, 30 open f$ for Window as #1 #1.tb,"!hide" wait
[EH] #1.tb,"!show" for a = 1 to 5 playwave f$ next wait
[done] #1.tb,"!hide" print "done" wait close #1 end
Take away the 'wait' statement and of course the window doesn't open at all. add a 'timer' in there anywhere and it doesn't really help what I don't understand is why the code to open the textbox won't work
I did put a short 'timer' statement after the open textbox statement to slow things down and that works, if I use playwave f$,sync. seems it was running too fast to catch the "!show" statement. async make the wav file play at lighting speed.
f$ = "L:\_WAV\1sec_Click.wav" nomainwin WindowWidth = 260 WindowHeight = 100 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2) textbox #1.tb, 10, 10, 200, 30 button #1.1, "ok", [EH],UL, 220, 10, 30, 30 open f$ for Window as #1 #1.tb,"!hide" wait
[EH] #1.tb,"!show" timer, 500, [play] wait [play] for a = 1 to 5 playwave f$,sync next 'wait
[done] timer 500, [stop] wait [stop] playwave "" #1.tb,"!hide" print "done" close #1 end
I wanted to attach the 1sec_Click.wav file, but couldn't find the attachment button!
|
|
Tasp
Full Member
Posts: 215
|
Post by Tasp on Nov 14, 2021 8:14:02 GMT -5
I'm not sure what the "ok" button is for, whether this is to start the timer or confirm the message you have entered.
Remember LB counts time in ms so 500 is half a second, so 1000 is 1 second (well close enough to 1 second)
'This is the correct way to cease a timer event Timer 0
The below code plays a windows ding for me (because I dont have your WAV file), each 1000 ticks (1 second), after the window is opened. When it gets to 5 or the user presses "ok" the program ends.
f$ = "L:\_WAV\1sec_Click.wav" nomainwin WindowWidth = 260 : WindowHeight = 100 UpperLeftX=int((DisplayWidth-WindowWidth)/2) : UpperLeftY=int((DisplayHeight-WindowHeight)/2)
textbox #1.tb, 10, 10, 200, 30 button #1.1, "ok", [done],UL, 220, 10, 30, 30 open f$ for Window as #1
[EH] #1.tb,"!show" timer, 1000, [play] WAIT
[play] a = a + 1 playwave f$,async IF a >= 5 THEN [done] WAIT
[done] timer 0 playwave "" #1.tb,"!hide" print "done" close #1 end
EDIT: Attach button is in top right corner. same line as the subject
|
|
|
Post by tsh73 on Nov 14, 2021 12:10:44 GMT -5
Indeed still not sure what a problem. You justfound that LB needs WAIT to show textbox you put
timer, 500, [play] wait [play] and it worked. But you said
- ok set minimal possible delay then
timer 1, [play] wait [play] timer 0 'so it fired only once
|
|
|
Post by Brandon Parker on Nov 14, 2021 17:49:33 GMT -5
Does the GUI need to do anything during this 5-second countdown? Does it need to be interactive during this time?
Is the WAV file shorter than 5 seconds? Can you create one that is 5 seconds long that way you only have to play it once? Can you share the WAV file that you are using?
This example (taken from the helpfile and amended) will show you how to do what you want to do, just replace WAV file path as noted. Also, you will want to take care with using the timer and mixing/matching branch label and subroutine usage.
NoMainWin options$(0) = "Cold Contact Phone Call" options$(1) = "Send Literature" options$(2) = "Follow Up Call" options$(3) = "Send Promotional" options$(4) = "Final Call" ListBox #Status.lstBox, options$(), selectionMade, 5, 35, 250, 90 Button #Status, "Cancel", cancelStatusSelection, UR, 15, 5 WindowWidth = 270 : WindowHeight = 180 Open "Select a contact status" For Window As #Status #Status.lstBox "singleclickselect"
'******Replace the string below with the full path to your WAV file PlayWave "Your WAV file here!", async Timer 5000, [hideListBox] Wait
[hideListBox] Timer 0 #Status.lstBox "Hide" Wait
Sub selectionMade handle$ #Status.lstBox "selection? selection$" 'Let's comment this out since activating a Notice inside 'a subroutine would cause an issue if the Timer's is fired ' and LB attempts to reach the branch labeled inside the subroutine 'Notice selection$ + " was chosen with listbox ";handle$ End Sub
Sub cancelStatusSelection handle$ Timer 0 Notice "Status selection cancelled" Close #Status End End Sub
{:0)
Brandon Parker
|
|
dkl
Full Member
Posts: 234
|
Post by dkl on Nov 14, 2021 20:49:32 GMT -5
I'm sorry , I really didn't explained myself very well, Never mind, the problem has been sorted! As always I really appreciated your time and help. In the last post above I was just trying explain what I wanted to do and what I had done in order to sort the problem. Sorry for any confusion I caused. The main problem though was 1. The hidden textbox would not open (adding the short timer response after the "!show" statement worked) 2. I couldn't get the playwave statement to run correctly with the timer statement I think I got myself in a mess, because now the code below works fine using a 5 sec wave file!! No additonal timer statements - nothing! Makes me wonder what on earth I was doing? textbox #1.tb, 10, 10, 200, 30 button #1.1, "ok", [EH],UL, 220, 10, 30, 30 open f$ for Window as #1 #1.tb,"!hide" wait [EH] #1.tb,"!show" playwave f$',sync [done] #1.tb,"!hide" print "done" wait
|
|
|
Post by tsh73 on Nov 15, 2021 3:40:02 GMT -5
I wonder why but 1) your last code did not show textbox on my machine without little TIMER/WAIT added 2) then shown, text box DOES NOT ALLOW INPUT while sound played So working version this * use small delay to show textbox *run playwave async *use timer to measure 5 seconds. This way I can enter stuff while wave is plaing.
ff$="C:\Users\user_name\Documents\Audacity\5sec440.wav"
textbox #1.tb, 10, 10, 200, 30 button #1.1, "ok", [EH],UL, 220, 10, 30, 30 open f$ for Window as #1 #1.tb,"!hide" wait
[EH] #1.tb,"!show" #1.tb, "*type here*" timer 1, [play] wait [play] timer 0 'playwave ff$',sync 'does not let input stuff playwave ff$ ,async
timer 5000, [done] wait
[done] timer 0 #1.tb,"!contents? var$" #1.tb,"!hide" print "done" print "got >";var$;"<" wait
|
|
dkl
Full Member
Posts: 234
|
Post by dkl on Nov 17, 2021 6:41:25 GMT -5
tsh73 Sorry for the delay I didn't see your post. Ahh.....that works for me too (although, I didn't actually need the ability to input data), but it's good to know for future reference. My last code was just to show how little I needed to get it to work (for me) after all the extra stuff I had trying to be doing. Thanks for taking the time to help improve it
|
|