From 0deb82a57ae3abefd44509dc88c546f6e5a94d1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Thu, 14 Jul 2016 15:39:54 +0200 Subject: Make 'wait' action interruptible --- helpers/music_file.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'helpers/music_file.py') diff --git a/helpers/music_file.py b/helpers/music_file.py index b40de1a..e6a340d 100644 --- a/helpers/music_file.py +++ b/helpers/music_file.py @@ -40,8 +40,8 @@ class MusicFile(Machine): self.audio_segment = None self.gain = gain self.music_lock = Lock("music__" + filename) + self.wait_event = threading.Event() - self.flag_paused = False threading.Thread(name = "MSMusicLoad", target = self.load).start() def on_enter_loading(self): @@ -109,6 +109,9 @@ class MusicFile(Machine): if self.is_loaded_stopping(): self.stopped() + def on_enter_loaded_stopped(self): + self.wait_event.set() + def play_callback(self, out_data, frame_count, time_info, status_flags): with self.music_lock: audio_segment = self.current_audio_segment.get_sample_slice_data( @@ -147,8 +150,8 @@ class MusicFile(Machine): return 20 * math.log10(max(volume, 0.0001) / 100) def wait_end(self): - # FIXME: todo - pass + self.wait_event.clear() + self.wait_event.wait() # Add some more functions to AudioSegments def get_sample_slice_data(self, start_sample=0, end_sample=float('inf')): -- cgit v1.2.3