Howdy, Stranger!

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

Supported by

Stopping MovieStim after 'escape'

Hello,

I'm working on an experiment that will record tobii eye tracking data during three movie clips. I would like to allow the experimenter to press "escape" during the clip to end it early and proceed to the next clip. However when I run it with my current code, the 1st clip (which has sound) continues to play sound throughout the other two clips and make the clips choppy and sometimes freeze. I've tried to add mov.stop() into my 'break while' loop but I get the error: AttributeError: 'ManagedSoundPlayer' object has no attribute 'stop'.

I would appreciate your help!

#coding: utf-8
#Import classes

import os
import pygaze
import pyglet
from pygaze import libtime
from pygaze.display import Display
from pygaze.screen import Screen
from pygaze.keyboard import Keyboard
from pygaze.eyetracker import EyeTracker
from pygaze.logfile import Logfile
import pygaze.libtime as timer

from psychopy import visual, core, event


from psychopy.visual import MovieStim


# Initialise a Display instance, using the default settings.
# (You can add a constants.py file to set these defaults.)
disp = Display()

kb = Keyboard(keylist=['left','right','escape'], timeout=2000)


# Get the handle to the active PsychoPy Window instance.
win = pygaze.expdisplay

# Initialise and calibrate an EyeTracker instance
tracker = EyeTracker(disp)
tracker.calibrate()

# Create a screen to show instructions on.
textscr = Screen()
textscr.draw_text("Press any key to start the next video.", fontsize=24)


# Initialise a PsychoPy MovieStim
mov = MovieStim(win, 'Experiment.mp4',size=[1920,1080], flipVert=False)


# Add the MovieStim to a PyGaze Screen instance.
# (The Screen object has a list of all its associated
# PsychoPy stimulus instances; you can add custom
# instances, like the MovieStim, and they will automatically
# be drawn each time you fill and show the Display.)
movscr = Screen()
movscr.screen.append(mov)

# Wait until the participant presses any key to start.
disp.fill(textscr)
disp.show()
kb.get_key(keylist=None, timeout=None, flush=True)


# Start recording from the eye tracker.
tracker.start_recording()

# Record the starting time, and log it to the tracker.
t1 = libtime.get_time()
tracker.log('START; Richards; time=%d' % (t1))
t0 = libtime.get_time()

# Run for the duration of the video
while mov.status != visual.FINISHED:

    # Fill the Display with the Screen. The right
    # frame from the video will automatically
    # be selected by PsychoPy.
    disp.fill(movscr)
    # Show the Display, and record its onset
    t1 = disp.show()
    # Log the screen flip.
    tracker.log('FLIP; time=%d' % (t1))
    # Check if the Escape key was pressed.
    key, presstime = kb.get_key(keylist=['Escape', 'escape'], timeout=1, flush=False)
    if key in ['Escape', 'escape']:
        # Break the while loop.
        tracker.log('ESCAPE; time=%d' % (presstime))
        mov.stop()
        break



# Stop recording from the eye tracker.
tracker.log('END; time=%d' % (t1))
tracker.stop_recording()


# Close the Display.


# Initialise a PsychoPy MovieStim
mov = MovieStim(win, 'Resting_somesound.mp4',size=[1920,1080], flipVert=False)


# Add the MovieStim to a PyGaze Screen instance.
# (The Screen object has a list of all its associated
# PsychoPy stimulus instances; you can add custom
# instances, like the MovieStim, and they will automatically
# be drawn each time you fill and show the Display.)
movscr = Screen()
movscr.screen.append(mov)

# Wait until the participant presses any key to start.
disp.fill(textscr)
disp.show()
kb.get_key(keylist=None, timeout=None, flush=True)


# Start recording from the eye tracker.
tracker.start_recording()

# Record the starting time, and log it to the tracker.
t1 = libtime.get_time()
tracker.log('START; Resting; time=%d' % (t1))
t0 = libtime.get_time()

# Run for the duration of the video
while mov.status != visual.FINISHED:

    # Fill the Display with the Screen. The right
    # frame from the video will automatically
    # be selected by PsychoPy.
    disp.fill(movscr)
    # Show the Display, and record its onset
    t1 = disp.show()
    # Log the screen flip.
    tracker.log('FLIP; time=%d' % (t1))
    # Check if the Escape key was pressed.
    key, presstime = kb.get_key(keylist=['Escape', 'escape'], timeout=1, flush=False)
    if key in ['Escape', 'escape']:
        # Break the while loop.
        mov.stop()
        tracker.log('ESCAPE; time=%d' % (presstime))
        break


# Stop recording from the eye tracker.
tracker.log('END; time=%d' % (t1))
tracker.stop_recording()



# Initialise a PsychoPy MovieStim
mov = MovieStim(win, 'VPCstim3.m4v',size=[1920,1080], flipVert=False)


# Add the MovieStim to a PyGaze Screen instance.
# (The Screen object has a list of all its associated
# PsychoPy stimulus instances; you can add custom
# instances, like the MovieStim, and they will automatically
# be drawn each time you fill and show the Display.)
movscr = Screen()
movscr.screen.append(mov)

# Wait until the participant presses any key to start.
disp.fill(textscr)
disp.show()
kb.get_key(keylist=None, timeout=None, flush=True)


# Start recording from the eye tracker.
tracker.start_recording()

# Record the starting time, and log it to the tracker.
t1 = libtime.get_time()
tracker.log('START; VPC; time=%d' % (t1))
t0 = libtime.get_time()

# Run for the duration of the video
while mov.status != visual.FINISHED:

    # Fill the Display with the Screen. The right
    # frame from the video will automatically
    # be selected by PsychoPy.
    disp.fill(movscr)
    # Show the Display, and record its onset
    t1 = disp.show()
    # Log the screen flip.
    tracker.log('FLIP; time=%d' % (t1))
    # Check if the Escape key was pressed.
    key, presstime = kb.get_key(keylist=['Escape', 'escape'], timeout=1, flush=False)
    if key in ['Escape', 'escape']:
        # Break the while loop.
        tracker.log('ESCAPE; time=%d' % (presstime))
        mov.stop()
        break



# Stop recording from the eye tracker.
tracker.log('END; time=%d' % (t1))
tracker.stop_recording()




# Close the connection to the tracker.
tracker.close()

# Close the Display.
disp.close()

Comments

  • Hi,

    Which version of psychopy do you use?

    You can find out by running:

    import psychopy
    print(psychopy.__version__)
    

    Also, this discussion on the psychopy github, might be useful.

    eduard

  • Hi Eduard,

    Thanks for your response.
    I'm using psychopy version 1.82.01. Perhaps this is old? Is there any easy way to uninstall psychopy so I can install the most updated version?

    I've also posted this on the psychopy forums as well, I appreciate your help anyway!

    Annie

  • edited March 30

    Hi Annie,

    Maybe you can try updating your psychopy within Opensesame.

    Run these lines in the debug window:

    import pip
    pip.main(['install', 'psychopy', '--upgrade'])
    

    as explained here: http://osdoc.cogsci.nl/3.2/manual/environment/

    Good luck,
    Eduard

Sign In or Register to comment.