Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed May 11, 2024
1 parent a4180c7 commit a0d01a2
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions ovos_audio/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ def load_services(self):
else:
local += s


# Sort services so local services are checked first
self.service = local + remote

Expand Down Expand Up @@ -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):
"""
Expand All @@ -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):
"""
Expand All @@ -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):
"""
Expand Down Expand Up @@ -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})
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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}")
Expand Down

0 comments on commit a0d01a2

Please sign in to comment.