Skip to content

Commit

Permalink
fix/end_of_track (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl authored Aug 6, 2024
1 parent 57ea267 commit ad92ee4
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions ovos_plugin_mpv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self, config, bus=None, name='ovos_mpv'):
def init_mpv(self):
self.mpv = MPV()
self.mpv.volume = self.normal_volume
self.mpv.bind_property_observer("eof-reached", self.handle_track_end)
self.mpv.bind_property_observer("eof-reached", self.handle_track_eof_status)
self.mpv.bind_property_observer("time-pos", self.update_playback_time)

# TODO - doesnt seem to be called on bad tracks requested?
Expand All @@ -43,22 +43,23 @@ def check_start_timeout(self, message):
f" is the uri valid? {self._now_playing}")
self.handle_mpv_error("timeout")

def handle_track_end(self, key, val):
if val is None:
self._started.clear()
def handle_track_eof_status(self, key, val):
LOG.debug(f"MPV EOF event: {key} - {val}")
if val is None and not self._started.is_set():
# NOTE: a bus event is used otherwise we block the MPV monitor thread with self._started.wait()
self.bus.emit(Message("ovos.mpv.timeout_check"))
return

if val is False:
self._started.set()
LOG.debug('MPV playback start')
if self._track_start_callback:
self._track_start_callback(self.track_info().get('name', "track"))
else:
elif self._started.is_set():
LOG.debug('MPV playback ended')
self._now_playing = None
if self._track_start_callback:
self._track_start_callback(None)
self._started.clear()

def handle_mpv_error(self, *args, **kwargs):
self.ocp_error()
Expand Down Expand Up @@ -100,6 +101,7 @@ def play(self, repeat=False):
""" Play playlist using mpv. """
if not self.mpv:
self.init_mpv()
self._started.clear()
self.mpv.play(self._now_playing)

def stop(self):
Expand Down

0 comments on commit ad92ee4

Please sign in to comment.