我附上了我的代码。基本上,一切都运行良好,除了视频没有正确恢复播放应该。音频继续,但视频无法正常恢复。请帮忙。我基本上已经对所有内容进行了评论,但为了概述(因为我无法在没有上下文的情况下发布),我的代码会显示一个对话框并暂停视频。如果密码不匹配,则会重新提示用户,直到他们输入正确的密码。正确输入密码后,视频应恢复正常。另外,我知道Python使用Lists,所以请原谅我在代码中将它们称为数组。我刚来自C,这就是我以前所做的。我将纠正这一进展。
#!/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 :(得分:0)
这是在心理学论坛上讨论的。无需交叉发布