@@ -354,30 +354,23 @@ class PlayControl:
354354 def __init__ (self , count = 1 , infinite = False ):
355355 self .count = count
356356 self .infinite = infinite
357- self ._stop_locks = [True , True ] # [once, many ]
357+ self ._stop_locks = [True ]
358358 self ._current_count = 0
359- self ._play_once_thread = None
360- self ._play_many_thread = None
359+ self ._play_thread = None
361360
362- def _play_once (self , capture , append_function = None ):
361+ def _play (self , capture , append_function = None ):
363362 for line in capture :
364- if self ._stop_locks [ 0 ] : break
363+ if self .is_stoped () : break
365364 exec (line )
366- self ._stop_locks [0 ] = True
367- if append_function :
368- append_function ()
369-
370- def _play_many (self , capture , append_function = None ):
371- self .current_count = 0
372- while (self .current_count < self .count or self .infinite )\
373- and not self ._stop_locks [1 ]:
374- self ._stop_locks [0 ] = False
375- self ._play_once_thread = self ._start_thread (self ._play_once , capture )
376- self ._play_once_thread .join ()
377- self .current_count += 1
378- self ._stop_locks = [True , True ]
379- if append_function :
380- append_function ()
365+ self ._current_count += 1
366+ print ('starting again' )
367+ if self ._current_count < self .count or self .infinite \
368+ and not self .is_stoped ():
369+ self ._play (capture , append_function )
370+ else :
371+ self .stop ()
372+ if append_function :
373+ append_function ()
381374
382375 def _start_thread (self , target , * args , daemon = False ):
383376 thread = Thread (target = target , args = (* args ,))
@@ -392,10 +385,10 @@ def set_config(self, count, infinite):
392385
393386 def get_current_count (self ):
394387 """Returns the current playback time"""
395- return current_count
388+ return self . _current_count
396389
397390 def is_stoped (self ):
398- return self ._stop_locks [0 ] and self . _stop_locks [ 1 ]
391+ return self ._stop_locks [0 ]
399392
400393 def play (self , capture , append_function = None ):
401394 """Starts playback according with configs setted
@@ -404,17 +397,13 @@ def play(self, capture, append_function=None):
404397 :param append_function: a function to be executed after
405398 a playback
406399 """
407- if self .infinite or self .count > 1 :
408- self ._stop_locks = [False , False ]
409- self ._start_thread (self ._play_many , capture ,
410- append_function )
411- else :
412- self ._stop_locks [0 ] = False
413- self ._start_thread (self ._play_once , capture ,
414- append_function )
400+ self ._stop_locks [0 ] = False
401+ self ._current_count = 0
402+ self ._play_thread = self ._start_thread (self ._play , capture ,
403+ append_function )
415404
416405 def stop (self ):
417- self ._stop_locks = [ True , True ]
406+ self ._stop_locks [ 0 ] = True
418407
419408
420409class PlayInterface :
0 commit comments