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

    Buy Me A Coffee

  • 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 2018

    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

    Buy Me A Coffee

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