2017-02-27 18 views
0

コードを添付しています。基本的には、ビデオが正常に再生を再開しない限り、すべて正常に動作します。オーディオは継続しますが、ビデオは正常に再開しません。助けてください。私は基本的にすべてをコメントアウトしましたが、(コンテキストなしで投稿できないため)概要を与えるために、私のコードはダイアログボックスを表示し、ビデオを一時停止します。パスワードが一致しない場合、ユーザーは正しいパスワードを入力するまで再入力されます。パスワードが正しく入力されると、ビデオは通常どおり再開されます。また、私はPythonがListを使用していることを知っていますので、私のコードでそれらを配列として参照することはできません。私はちょうどCから来ているので、それは私が慣れていたものです。私はこれを前向きに修正します。一時停止後にPsychopyビデオが正しく再生されない

#!/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() 

答えて

0

これは、代わりにpsychopyフォーラムで議論されています。クロスポストする必要はありません

関連する問題