aboutsummaryrefslogtreecommitdiff
path: root/helpers/music_file.py
diff options
context:
space:
mode:
Diffstat (limited to 'helpers/music_file.py')
-rw-r--r--helpers/music_file.py22
1 files changed, 20 insertions, 2 deletions
diff --git a/helpers/music_file.py b/helpers/music_file.py
index ccf60ce..aeba1b9 100644
--- a/helpers/music_file.py
+++ b/helpers/music_file.py
@@ -32,7 +32,8 @@ class MusicFile:
32 { 32 {
33 'trigger': 'load', 33 'trigger': 'load',
34 'source': 'initial', 34 'source': 'initial',
35 'dest': 'loading' 35 'dest': 'loading',
36 'after': 'poll_loaded'
36 }, 37 },
37 { 38 {
38 'trigger': 'fail', 39 'trigger': 'fail',
@@ -68,7 +69,8 @@ class MusicFile:
68 'trigger': 'stopped', 69 'trigger': 'stopped',
69 'source': '*', 70 'source': '*',
70 'dest': 'loaded', 71 'dest': 'loaded',
71 'before': 'trigger_stopped_events' 72 'before': 'trigger_stopped_events',
73 'conditions': ['is_in_use']
72 } 74 }
73 ] 75 ]
74 76
@@ -77,6 +79,7 @@ class MusicFile:
77 transitions=self.TRANSITIONS, initial='initial', 79 transitions=self.TRANSITIONS, initial='initial',
78 ignore_invalid_triggers=True) 80 ignore_invalid_triggers=True)
79 81
82 self.loaded_callbacks = []
80 self.mapping = mapping 83 self.mapping = mapping
81 self.filename = filename 84 self.filename = filename
82 self.name = name or filename 85 self.name = name or filename
@@ -230,6 +233,21 @@ class MusicFile:
230 self.wait_event.clear() 233 self.wait_event.clear()
231 self.wait_event.wait() 234 self.wait_event.wait()
232 235
236 # Let other subscribe for an event when they are ready
237 def subscribe_loaded(self, callback):
238 with file_lock:
239 if self.is_loaded(allow_substates=True):
240 callback(True)
241 elif self.is_failed():
242 callback(False)
243 else:
244 self.loaded_callbacks.append(callback)
245
246 def poll_loaded(self):
247 for callback in self.loaded_callbacks:
248 callback(self.is_loaded())
249 self.loaded_callbacks = []
250
233 # Callbacks 251 # Callbacks
234 def finished_callback(self): 252 def finished_callback(self):
235 self.stopped() 253 self.stopped()