Help with 10 second pauses of a video

Hello!
Currently I am working on an experiment related to event segmentation. I am trying to create a custom code which allows the participant to pause a video stimulus (using ‘space’) and for the pause to last 10 seconds and automatically resume. Here is my code, hope to figure out why it is not working.
Begin experiment

    is_paused = False
    pause_timer = core.Clock()  # Timer to track the pause duration
    pause_times_SegmentationTraining = []  # List to store the pause times

Each frame

    if is_paused:
        if pause_timer.getTime() >= 10:  # Pause for 10 seconds
            is_paused = False
            SegmentationTraining.play()  # Resume the video
    else:
        keys = event.getKeys()
        if 'space' in keys:
            is_paused = True
            SegmentationTraining.pause() 
  pause_times_SegmentationTraining.append(SegmentationTraining.getCurrentFrameNumber())

End routine

    thisExp.addData('pause_times_SegmentationTraining', pause_times_SegmentationTraining)

Hope somebody can help:))

Fixed it!
Wish you all fellow experimenters a smooth sail through the seas of science:)

Well done! What was the fix?

Thanks! The timer was not resetting properly so I amended the code and replaced ‘space’ with a letter key because ‘space’ is used to end the previous routine, and this was creating issues, e.g. the video doesn’t start right away because pressing space from the last routine is detected, and it pauses the video for 10 seconds before it has even started…

if is_paused:
    if pause_timer.getTime() >= 10:  # Pause for 10 seconds
        is_paused = False
        **pause_timer = core.Clock()** #Reset timer
        SegmentationTraining.play()  # Resume the video
else:
    keys = event.getKeys()
    **if 'n' in keys:**
        is_paused = True
        SegmentationTraining.pause()  # Pause the video

The amendment of the code is highlighted.

1 Like