Use lock around play and stop
Moves the stopping logic to separate method to be able to call from
locked contexts
@@ -326,6 +326,16 @@ class AudioService:
if self.current:
self.current.previous()
+ def _perform_stop(self):
+ """Stop audioservice if active."""
+ if self.current:
+ name = self.current.name
+ if self.current.stop():
+ self.bus.emit(Message("mycroft.stop.handled",
+ {"by": "audio:" + name}))
+
+ self.current = None
+
def _stop(self, message=None):
"""
Handler for mycroft.stop. Stops any playing service.
@@ -336,13 +346,8 @@ class AudioService:
if time.monotonic() - self.play_start_time > 1:
LOG.debug('stopping all playing services')
with self.service_lock:
- if self.current:
- name = self.current.name
- if self.current.stop():
- self.bus.emit(Message("mycroft.stop.handled",
- {"by": "audio:" + name}))
-
- self.current = None
+ self._perform_stop()
+ LOG.info('END Stop')
def _lower_volume(self, message=None):
"""
@@ -400,7 +405,7 @@ class AudioService:
prefered_service: indecates the service the user prefer to play
the tracks.
"""
- self._stop()
+ self._perform_stop()
if isinstance(tracks[0], str):
uri_type = tracks[0].split(':')[0]
@@ -434,6 +439,7 @@ class AudioService:
def _queue(self, message):
if self.current:
+ with self.service_lock:
tracks = message.data['tracks']
self.current.add_list(tracks)
else:
@@ -448,6 +454,7 @@ class AudioService:
Args:
message: message bus message, not used but required
"""
+ with self.service_lock:
tracks = message.data['tracks']
repeat = message.data.get('repeat', False)
# Find if the user wants to use a specific backend
@@ -460,6 +467,7 @@ class AudioService:
else:
prefered_service = None
self.play(tracks, prefered_service, repeat)
+ time.sleep(0.5)
def _track_info(self, message):
"""
