# HG changeset patch # User drewp@bigasterisk.com # Date 2005-06-13 03:16:19 # Node ID 0a223937946690dda3df7a1adfb64e701ac962a0 # Parent 76e326329610f164809b8f524b6d7078705bfba8 added autopause. workaround for mpd's incorrect times diff --git a/bin/ascoltami b/bin/ascoltami --- a/bin/ascoltami +++ b/bin/ascoltami @@ -80,9 +80,12 @@ class Player: self.pollStatus() + self.autopausedthissong = False # a song only autopauses once + self.mpd_is_lying = False # mpd reports bad times in certain intervals def smoothCurrentTime(self): """like self.current_time.get, but more accurate""" + if self.last_poll_time and self.state.get() == 'play': dt = time.time() - self.last_poll_time else: @@ -102,20 +105,41 @@ class Player: if hasattr(stat, 'time_elapsed'): - if stat.song == 1: - t = stat.time_elapsed - elif stat.song == 0: - t = stat.time_elapsed - stat.time_total - elif stat.song == 2: - t = self.total_time.get() + stat.time_elapsed + elapsed = stat.time_elapsed + songnum = stat.song + total = stat.time_total + if self.mpd_is_lying and elapsed < 3: + self.mpd_is_lying = False + + # mpd lies about elapsed, song, and total during the last + # .5sec of each song. so we coast through that part + if elapsed > total - .75 or self.mpd_is_lying: + if not self.mpd_is_lying: + self.mpd_is_lying = True + self.true_song_total = songnum, total + self.marked_time = time.time() + self.marked_val = elapsed + elapsed = self.marked_val + (time.time() - self.marked_time) + songnum, total = self.true_song_total + + if songnum == 1: + t = elapsed + elif songnum == 0: + t = elapsed - total + elif songnum == 2: + t = self.total_time.get() + elapsed self.current_time.set(t) + + self.last_poll_time = time.time() - self.last_poll_time = time.time() + self.check_autopause() reactor.callLater(.05, self.pollStatus) def play(self, song_path): + + self.autopausedthissong = False self.mpd.clear() self.mpd.add(showconfig.songInMpd(self.pre_post_names[0])) self.mpd.add(showconfig.songInMpd(song_path)) @@ -131,12 +155,22 @@ class Player: self.total_time.set(stat.time_total) self.mpd.seek(seconds=0, song=0) + def check_autopause(self): + pause_time = self.total_time.get() + 10 + if (not self.autopausedthissong and + self.state.get() == "play" and + self.current_time.get() > pause_time): + self.autopausedthissong = True + self.mpd.pause() + def stop(self): self.mpd.seek(seconds=0, song=0) self.mpd.stop() def seek_to(self, time): if time < 0: + # seeking to anything within my 4-sec silence ogg goes + # right to zero. maybe ogg seeking is too coarse? self.mpd.seek(seconds=time - (-4), song=0) elif time > self.total_time.get(): self.mpd.seek(seconds=time - self.total_time.get(), song=2) @@ -277,10 +311,11 @@ class ControlButtons(tk.Frame): tk.Frame.__init__(self,master,bg='black') self.statebuttons = {} # lowercased name : Button - for txt,cmd,key in (('Stop', player.stop, ""), - ('Pause', player.play_pause_toggle, ""), - ('Skip Intro',lambda: player.seek_to(-.5), ""), - ): + for txt,cmd,key in [ + ('Stop', player.stop, ""), + ('Pause', player.play_pause_toggle, ""), + ('Skip Intro',lambda: player.seek_to(0), ""), + ]: b = tk.Button(self, text=txt, command=cmd, font='arial 16 bold', height=3,**appstyle) b.pack(side='left', fill='x', expand=1) @@ -290,7 +325,6 @@ class ControlButtons(tk.Frame): def update_state_buttons(self,*args): state = player.state.get() - print "State", state if state in ('stop', 'pause'): self.statebuttons['pause']['text'] = 'Play'