Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

[solved] Stopping a video with a key release?

edited December 2014 in OpenSesame

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

  • edited December 2014

    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

  • edited 4:57AM

    Hi Adam,

    Your last idea is just what I had in mind. So, what you probably want the do is getting an inline_script in which you have your loop waiting 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_scripts and use its functionality to present videos. I can't really tell you which backend is the best for video presentation. Xpyriment has at least video functionality

    Here is a small description how to load the libraries into opensesame.
    Basically, it boils down to:

    from expyriment import stimuli
    video = stimuli.Video(file)
    

    I hope this helps. Sorry for not giving more detailed information, but I haven't work with it yet myself.

    Good luck,

    Eduard

    Buy Me A Coffee

  • edited December 2014

    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 to KEYDOWN - so I changed that to KEYUP and 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 tried exp.set() and set() and self.log() and exp.log() and log() but all throw errors. I'm sure I'm missing something simple here.

    Here's my mods to the code in video_player.py:

    """
    Handles the actual video playback
    """
    
    # Log the onset time of the item
    self.set_item_onset()
    
    t = pygame.time.get_ticks()
    start_t = t
    self.set('keydowntime', start_t)
    
    
    # Loop until a key is pressed
    go = True
    while go:
    
        # Get the frame     
        self.src = cv.QueryFrame(self.video)
    
        # Check for the end of the video
        if self.src == None:
            break       
    
        # Resize if requested and convert the resulting image to
        # RGB format, which is compatible with PyGame
        if self._fullscreen:
            cv.Resize(self.src, self.src_tmp)
            cv.CvtColor(self.src_tmp, self.src_rgb, cv.CV_BGR2RGB)
        else:
            cv.CvtColor(self.src, self.src_rgb, cv.CV_BGR2RGB)
    
        # Convert the image to PyGame format
        pg_img = pygame.image.frombuffer(self.src_rgb.tostring(), cv.GetSize(self.src_rgb), "RGB")
    
        # Show the video frame!
        self.experiment.surface.blit(pg_img, (self._x, self._y))    
        pygame.display.flip()
    
        # Pause before jumping to the next frame
        pygame.time.wait(self.frame_dur - pygame.time.get_ticks() + t)
        t = pygame.time.get_ticks()
    
        if type(self.duration) == int:          
            # Wait for a specified duration
            if t - start_t >= self.duration:
                go = False
    
        # Catch escape presses
        for event in pygame.event.get():        
    
            if event.type == KEYUP:                 
                if event.key == pygame.K_ESCAPE:
                    raise exceptions.runtime_error("The escape key was pressed.")
                if self.duration == "keypress": 
                    keyup_t = pygame.time.get_ticks()
                    self.set('keyuptime', keyup_t)
                    keyreleasert = keyup_t - start_t
                    self.set('keyreleasert', keyreleasert)
                    print 'key was released at %d ms' % (keyreleasert)
                    go = False
    
    
    
            if event.type == MOUSEBUTTONDOWN and self.duration == "mouseclick":
                go = False
    
  • edited 4:57AM

    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, self doesn't refer to the experiment, but to the video player class. 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

    Buy Me A Coffee

  • edited 4:57AM

    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

Sign In or Register to comment.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu http://45.77.173.118/ Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games