[solved] Stopping a video with a key release?
Hi,
I'm working hard on developing an experiment (for sign language research) where the user presses and holds down a key to start watching a video and then releases it to start signing and the video stops, and we measure the time elapsed from holding down the key to the key release (reaction time, really).
I've managed to implement a script to collect key release RT (thanks Eduard, see thread). That part works, but I can't seem to figure out how to make that script work with the video_player (especially where I specify the "duration" - keypress?) so that the video stops when the key is released.
Here's a link to my experiment file. Filedropper
Thanks for any help you can provide,
Adam
Comments
Hello,
I did some more work on this via a lot of googling through this forum. I now think a parallel structure might work, where one side looks for the key release event, while the other side presents the video.
I talked with my colleague and we no longer need the video to actually stop when the key is released. So the problem is simpler now...I just need it to record the time when a key is pressed and held down, starting a video, to the time the key is released.
I am able to make the first part work using an inline script polling for pygame.KEYDOWN. Then the video runs. Then I have a second inline script that measures RT but it does not continue from when the video started...I have to release the key and then press it down and then release it again and then a RT is recorded but that's not what I want at all.
(Instruction - "hold down key to play") -> key is held down -> video plays -> key is released and RT is recorded from key_down. (video can keep playing; it's very short anyway)
Here's my latest attempt at this--Dropbox link
I am thinking maybe I need to replace the loop/sequence with one big long inline script that calls for the video player and pygame.KEYDOWN and pygame.KEYUP but I am having difficulty finding documentation on how to call video player in the inline script??
Thanks again,
Adam
Hi Adam,
Your last idea is just what I had in mind. So, what you probably want the do is getting an
inline_scriptin which you have yourloopwaiting for key presses and releases. As soon as you hold on specific key you start your video and wait until the key release. The only thing I am unsure about is, whether you can continue monitorring the keypress situation while the video is playing, or you have to wait until the video stops to be able to continue looping. I think it should be fine though.I recommend you're loading on of the 'backends' in the
inline_scriptsand use its functionality to present videos. I can't really tell you whichbackendis the best for video presentation.Xpyrimenthas at least video functionalityHere is a small description how to load the libraries into opensesame.
Basically, it boils down to:
I hope this helps. Sorry for not giving more detailed information, but I haven't work with it yet myself.
Good luck,
Eduard
Eduard,
Thanks for your help. I tried those two lines you gave me, and it didn't work - so I went for some more searching on how to build while loops with videos and got pretty overwhelmed.
Then I had an idea. I looked in
video_player.py(the plugin file itself) and found a line that referenced toKEYDOWN- so I changed that toKEYUPand also added a few more lines to print out reaction time in the debug window.IT WORKED PERFECTLY! Yes, I know, this basically breaks video_player's normal functionality, but it will do for now. This approach seems easier than any other approach I've tried.
Now the issue is, it logs the reaction times as NA...I find this puzzling as it prints out just fine (and very accurately) to the debug window, but in the log file it's NA. I feel I'm missing something simple here. Shouldn't
self.set('keydowntime', start_t)work fine? I triedexp.set()andset()andself.log()andexp.log()andlog()but all throw errors. I'm sure I'm missing something simple here.Here's my mods to the code in
video_player.py:Sorry for the confusion, Adam. The two lines were not supposed to work (well, I wouldn't mind if they did, though). It should just demonstrate how you can access
expyriments functionality, in general. You would have to check their documentation to make it work, but I am quite sure it should be possible.I think the reason why you're not logging anything right now is that you're trying to set experiment variables outside an experiment. At the position where you modified the file,
selfdoesn't refer to the experiment, but to thevideo playerclass. The actual experiment is an attribute of the class, though, so you should be able to set its variables if you use:self.experiment.set('keydowntime', start_t). Can you check that?Best,
Eduard
That works perfectly. THANK YOU, Eduard! I really, really appreciate this. Now we can do our study. Let me know if there's anything I can do for you!
Adam