Changeset - 1082f0725c32
[Not reviewed]
default
0 1 0
drewp@bigasterisk.com - 8 months ago 2024-05-28 22:34:03
drewp@bigasterisk.com
fix PlayerState semantics
1 file changed with 6 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/light9/ascoltami/player.py
Show inline comments
 
@@ -56,31 +56,33 @@ class Player:
 

	
 
    async def _watchTime(self):
 
        while True:
 
            now = time.time()
 
            try:
 
                self._pollForMessages()
 
                t = self.currentTime()
 
                # log.debug("watch %s < %s < %s", self._lastWatchTime, self._autoStopTime, t)
 
                if self._lastWatchTime < self._autoStopTime < t:
 
                    log.info("autostop")
 
                    self.pause()
 

	
 
                eos = t >= self.duration() - .1  #todo
 
                playing = self.isPlaying() and not eos
 
                ps = PlayerState(
 
                    song=self._getSongFileUri(),
 
                    duration=round(self.duration(), 2),
 
                    wallStartTime=round(now - t, 2) if self.isPlaying() else None,
 
                    playing=self.isPlaying(),
 
                    pausedSongTime=None if self.isPlaying() else t,
 
                    endOfSong=t >= self.duration() - .1,  #todo
 
                    wallStartTime=round(now - t, 2) if playing else None,
 
                    playing=playing,
 
                    pausedSongTime=None if playing else t,
 
                    endOfSong=eos,
 
                )
 

	
 
                if self.playerState != ps:
 
                    self.onStateChange(ps)
 
                    self.playerState = ps
 

	
 
                self._lastWatchTime = t
 
            except Exception:
 
                traceback.print_exc()
 
            await asyncio.sleep(0.5)
 

	
 
    def _watchForMessages(self, bus):
0 comments (0 inline, 0 general)