2017-02-27 4 views
0

Ich füge meinen Code an. Im Prinzip funktioniert alles einwandfrei, außer dass das Video nicht ordnungsgemäß wieder abgespielt wird. Das Audio wird fortgesetzt, aber das Video wird nicht ordnungsgemäß fortgesetzt. Bitte helfen Sie. Ich habe im Grunde alles kommentiert, aber um einen Überblick zu geben (weil ich nicht ohne Kontext posten kann), zeigt mein Code ein Dialogfeld an und pausiert das Video. Wenn die Kennwörter nicht übereinstimmen, wird der Benutzer erneut aufgefordert, bis er das richtige Kennwort eingibt. Sobald das Passwort korrekt eingegeben wurde, sollte das Video wie gewohnt fortgesetzt werden. Außerdem weiß ich, dass Python Listen verwendet, also entschuldige, dass ich sie als Arrays in meinem Code verstanden habe. Ich komme gerade von C, also bin ich das gewohnt. Ich werde das korrigieren.Psychopy Video spielt nicht richtig nach Pause

#!/usr/bin/env python2 
# -*- coding: utf-8 -*- 

############################################################ 
#  This program is designed to play a video   # 
#  where the user has to enter different passwords  # 
#  to resume playing of the video file     # 
############################################################ 

from __future__ import division 

from psychopy import visual, core, event, gui 
import time, os 
from timeit import default_timer 

videopath = r'./Devin.mp4' 
videopath = os.path.join(os.getcwd(), videopath) 
if not os.path.exists(videopath): 
    raise RuntimeError("Video File could not be found:" + videopath) 

win = visual.Window([2500, 1600]) 

# Create your movie stim. 
mov = visual.MovieStim2(win, videopath, 
    size = 1280, 
    pos=[0,420], 
    flipVert=False, flipHoriz=False, 
    loop=False) 

globalClock = core.Clock() # May use this to end the video 

#Passwords that are required to resume playing the video 
progPassword = ['doggy', 'garbage', 'actively', 'caring'] 

# The intervals in time[] indicate when the video pause occurs in seconds 
# The times indicate the seconds after each previous interval passes 
# The first interval is 0 + 90, so the pause occurs at 90 seconds 
# The times[2] represents 90 + 135, or 225 seconds. 
# So, the second pause occurs after a 3:45 progression into the movie 
#times = [90, 135, 210, 285] 
times = [5, 5, 5, 5] 
j = (len(progPassword) - 1) # Number of entries in the array 'password' -- count the commas in progPassword, that's the value of j 
print(j) 
# n = progPassword[-1] <-- refers to the last entry in an array in python 

"""Program Start""" 

i = 0 # Starts i = 0 because arrays are indexed at 0. times[0] corresponds to 90 seconds 
while i <= j: 
    start = time.time() # Starting a timer to run in tandem with the video 
    future = start + times[i] 
    print(future) 
    mov.play() 
    while time.time() < future: # Plays the video for the corresponding interval in time[i] 
     mov.draw() 
     win.flip() 

    mov.pause()  
    while time.time() > future: # Pauses the video and displays my dialogue box prompting 
     myDlg = gui.Dlg(title = 'The password is: ' + progPassword[i]) 
     myDlg.addField('Please enter the password') 
     myDlg.show() 
     if myDlg.OK: 
      userPassword = myDlg.data[0] 
      if userPassword == progPassword[i]: 
       i += 1 
       print(i) 
       break 
      if userPassword != progPassword[i] or myDlg != myDlg.OK: 
       continue # If user doesn't enter the correct password, then the loop repeats until the correct password is entered 

"""Playing movie until EOF""" 

mov.play() 
while i > j: 
    mov.draw() 
    win.flip() 

win.close() 
core.quit() 

Antwort

0

Dies wird auf dem Psychopy Forum diskutiert. Keine Notwendigkeit,

zu kreuzen