我正在做一个关于制作定制媒体播放器的学校项目。我在网上有一些我一直在使用的源代码。我想添加另一个新功能,即制作源代码没有的播放列表。
但是,当我尝试拖动窗口时,我遇到了一个错误,即窗口“停止响应”。我无法单击任何内容,因为我的光标显示“加载标志”(圆形光标),似乎有一些背景踏板正在运行。
我试过让它运行而不拖动它,它似乎工作正常。
你们有谁知道为什么当我使用函数“time.sleep(second)”时会出现这个问题?
参考: http: //www.blog.pythonlibrary.org/2010/07/24/wxpython-creating-a-simple-media-player/
逻辑(代码):
def load_playlist(self, event):
playlist = ["D:\Videos\test1.mp4", "D:\Videos\test2.avi"]
for path in playlist:
#calculate each media file duration
ffmpeg_command = ['C:\\MPlayer-rtm-svn-31170\\ffmpeg.exe', '-i' , path]
pipe = subprocess.Popen(ffmpeg_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
results = pipe.communicate()
#Regular expression to get the duration
length_regexp = 'Duration: (\d{2}):(\d{2}):(\d{2})\.\d+,'
re_length = re.compile(length_regexp)
# find the matches using the regexp that to compare with the buffer/string
matches = re_length.search(str(results))
#print matches
hour = matches.group(1)
minute = matches.group(2)
second = matches.group(3)
#Converting to second
hour_to_second = int(hour) * 60 * 60
minute_to_second = int(minute) * 60
second_to_second = int(second)
num_second = hour_to_second + minute_to_second + second_to_second
print num_second
#Play the media file
trackPath = '"%s"' % path.replace("\\", "/")
self.mplayer.Loadfile(trackPath)
#Sleep for the duration of second(s) for the video before jumping to another video
time.sleep(num_second)