Howdy, Stranger!

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

Supported by

Playing a Video in Canvas

Hi there :)

I am conducting an experiment in OpenSesame where I need to make use of image and video stimuli.


When rendering the video stimuli through pygame or moviepy, they play in a separate window to the rest of my experiment on my canvas (i.e. a pygame or moviepy window). Is it possible to play videos on my canvas as well?


Here is a snippet of code used to play videos, although this does so in a separate window.


from moviepy.editor import VideoFileClip


simple_path = pool[var.simple_stim]

complex_path = pool[var.complex_stim]


# Function to display video

def display_video(video_path):

clip = VideoFileClip(video_path)

clip.preview()

clip.close()


# Check if the stimuli are videos or images

if var.complex_stim.endswith('.mp4'):

display_video(complex_path)

else:

my_canvas.image(complex_path, center=True, x=0, y=0, scale=var.image_scale)


my_canvas.show()


# Repeat the same for the simple stimulus

if var.simple_stim.endswith('.mp4'):

display_video(simple_path)

else:

my_canvas.image(simple_path, center=True, x=0, y=0, scale=var.image_scale)


my_canvas.show()


started_lookingaway = False

insp_dur = 0

disconnect_dur = 0

lookaway_dur = 0


var.t0 = time.time()

var.insp_dur = 0

var.lookaway_dur = 0

var.disconnect_dur = 0


var.insp_dur = 0 # Initialize var.insp_dur as an integer


while True:

x, y = eyetracker.sample()


if True: # eyetracker.connected():

if var.x_min < x < var.x_max and var.y_min < y < var.y_max:

# if on target log inspection duration and reset looking away timer

var.insp_dur = time.time() - var.t0 # Reassign var.insp_dur as an integer

# other code continues...


var.lookaway_dur = 0

else:

# If not on target append new time to looking away timer

var.lookaway_dur += (time.time() - var.t0)

# if looking away for 1 or more seconds, move on

if var.lookaway_dur >= 1:

break

else:

var.disconnect_dur += (time.time() - var.t0)

if var.disconnect_dur >= 1.5:

break

var.t0 = time.time()


my_canvas.clear()

my_canvas.show()

Sign In or Register to comment.