From a0d01a2618e8a5b7a2582640c928a935b721de28 Mon Sep 17 00:00:00 2001 From: miro Date: Sat, 11 May 2024 03:54:19 +0100 Subject: [PATCH] companion to https://github.com/OpenVoiceOS/ovos-plugin-manager/pull/226/ --- ovos_audio/audio.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/ovos_audio/audio.py b/ovos_audio/audio.py index d945272..1b4db9e 100644 --- a/ovos_audio/audio.py +++ b/ovos_audio/audio.py @@ -101,7 +101,6 @@ def load_services(self): else: local += s - # Sort services so local services are checked first self.service = local + remote @@ -163,11 +162,13 @@ def track_start(self, track): LOG.debug('New track coming up!') self.bus.emit(Message('mycroft.audio.playing_track', data={'track': track})) + self.current.ocp_start() else: # If no track is about to start last track of the queue has been # played. LOG.debug('End of playlist!') self.bus.emit(Message('mycroft.audio.queue_end')) + self.current.ocp_stop() def _pause(self, message=None): """ @@ -181,6 +182,7 @@ def _pause(self, message=None): return if self.current: self.current.pause() + self.current.ocp_pause() def _resume(self, message=None): """ @@ -193,6 +195,7 @@ def _resume(self, message=None): return if self.current: self.current.resume() + self.current.ocp_resume() def _next(self, message=None): """ @@ -227,6 +230,7 @@ def _perform_stop(self, message=None): if self.current: name = self.current.name if self.current.stop(): + self.current.ocp_stop() if message: msg = message.reply("mycroft.stop.handled", {"by": "audio:" + name}) @@ -345,10 +349,17 @@ def play(self, tracks, prefered_service, repeat=False): return if not selected_service.supports_mime_hints: tracks = [t[0] if isinstance(t, list) else t for t in tracks] - selected_service.clear_list() - selected_service.add_list(tracks) - selected_service.play(repeat) + self.current = selected_service + self.current.clear_list() + self.current.add_list(tracks) + + try: + self.current.play(repeat) + self.current.ocp_start() + except Exception as e: + LOG.exception(f"failed to play with {self.current}") + self.current.ocp_error() self.play_start_time = time.monotonic() def _is_message_for_service(self, message): @@ -390,7 +401,7 @@ def _play(self, message): if ('utterance' in message.data and s.name in message.data['utterance']): prefered_service = s - LOG.debug(s.name + ' would be prefered') + LOG.debug(s.name + ' would be preferred') break except Exception as e: LOG.error(f"failed to parse audio service name: {s}")