77
88
99class Emoticon :
10- def __init__ (self , file_path : list = [], window_size : list = []) -> None :
10+ def __init__ (self , file_path : list = [], window_size : list = [], loop = False ) -> None :
1111 """API for playing emoticons
1212
1313 Args:
@@ -19,6 +19,8 @@ def __init__(self, file_path: list = [], window_size: list = []) -> None:
1919 self .__window_size = window_size
2020 self .quit = False
2121 self .stop_play = False
22+ self .start_time = 0
23+ self .loop = loop
2224
2325 @property
2426 def file_path (self ):
@@ -73,17 +75,31 @@ def play(self):
7375 if self .quit :
7476 break
7577 while self .stop_play and self .quit == False :
76- pass
78+ if self .start_time == 0 :
79+ self .start_time = time .time () - t
80+ if self .start_time > 0 :
81+ t = time .time () - self .start_time
82+ self .start_time = 0
7783 ret , frame = cap .read ()
78- # print(frame)
7984 if frame is not None :
8085 cv .imshow (out_win , frame )
81- if cv .waitKey (1 ) & 0xFF == ord ('q' ) or ret == False :
82- if time .time () - t >= self .__file_path [index ][1 ]:
86+ if time .time () - t >= self .__file_path [index ][1 ]:
8387 index += 1
8488 if index >= len (self .__file_path ):
8589 index = 0
90+ t = time .time ()
91+ if cv .waitKey (1 ) & 0xFF == ord ('q' ) or ret == False :
8692 cap = cv .VideoCapture (self .__file_path [index ][0 ])
93+
94+ if time .time () - t >= self .__file_path [index ][1 ]:
95+ index += 1
96+ if index >= len (self .__file_path ):
97+ if self .loop :
98+ index = 0
99+ else :
100+ break
101+ t = time .time ()
102+ cap = cv .VideoCapture (self .__file_path [index ][0 ])
87103 if self .quit :
88104 break
89105 cap .release ()
@@ -94,6 +110,6 @@ def start(self):
94110 self .t = threading .Thread (target = self .play , daemon = True )
95111 self .t .start ()
96112
97- def joint (self ):
113+ def join (self ):
98114 """Wait for the thread playing the video to finish"""
99- self .t .joint ()
115+ self .t .join ()
0 commit comments