i'm working on a school project regarding making a customized media player. I've got some source code on the web which i have been using. I wanted to add in another new feature which is to make a playlist which the source code does not have.
However i encounter an error whereby the window "stop responding" when i try to drag the window around. I wasn't able to click on anything as it seem like there is some background tread running because my cursor show the "loading sign" (Circular cursor).
I have tried leaving it running without dragging it and it seems to work properly.
Do anyone of you happens to know why is this problem occuring when i uses the function "time.sleep(second)"?
Reference: http://www.blog.pythonlibrary.org/2010/07/24/wxpython-creating-a-simple-media-player/
Logic (code):
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)