Update playback pos more often, reset pos to 0 on stop.

This commit is contained in:
Matthew Stratford 2021-03-21 13:06:09 +00:00
parent 81eb8c7d1b
commit 1f66ec2ef2

View file

@ -442,6 +442,9 @@ class Player():
elif self.isPlaying: elif self.isPlaying:
# Get one last update in, incase we're about to pause/stop it. # Get one last update in, incase we're about to pause/stop it.
self.state.update("pos", max(0, mixer.music.get_pos()/1000)) self.state.update("pos", max(0, mixer.music.get_pos()/1000))
elif not self.isPaused:
self.state.update("pos", 0) # Reset back to 0 if stopped.
self.state.update("pos_offset", 0)
self.state.update("playing", self.isPlaying) self.state.update("playing", self.isPlaying)
self.state.update("loaded", self.isLoaded) self.state.update("loaded", self.isLoaded)
@ -450,7 +453,9 @@ class Player():
self.state.update("remaining", self.state.state["length"] - self.state.state["pos_true"]) self.state.update("remaining", self.state.state["length"] - self.state.state["pos_true"])
def _ping_times(self): def _ping_times(self):
if self.last_time_update == None or self.last_time_update + 1 < time.time():
UPDATES_FREQ_SECS = 0.2
if self.last_time_update == None or self.last_time_update + UPDATES_FREQ_SECS < time.time():
self.last_time_update = time.time() self.last_time_update = time.time()
self.out_q.put("POS:" + str(int(self.state.state["pos_true"]))) self.out_q.put("POS:" + str(int(self.state.state["pos_true"])))