changeset 292:e841bea500c3

guard against some errors when mpd is playing other music
author drewp@bigasterisk.com
date Sat, 18 Jun 2005 15:41:28 +0000
parents 6c3b487e7bbc
children 1c590824dd14
files bin/ascoltami
diffstat 1 files changed, 32 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/bin/ascoltami	Sat Jun 18 07:35:29 2005 +0000
+++ b/bin/ascoltami	Sat Jun 18 15:41:28 2005 +0000
@@ -111,43 +111,44 @@
         self.mpd.status().addCallback(self.pollStatus2)
         
     def pollStatus2(self, stat):
-
-        if self.state.get() != stat.state:
-            self.state.set(stat.state)
+        try:
+            if self.state.get() != stat.state:
+                self.state.set(stat.state)
 
 
-        if hasattr(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
+            if hasattr(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
+                # 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
 
-            self.current_time.set(t)
-            
-            self.last_poll_time = time.time()
+                t = -1
+                if songnum == 1:
+                    t = elapsed
+                elif songnum == 0:
+                    t = elapsed - total
+                elif songnum == 2:
+                    t = self.total_time.get() + elapsed
 
-        self.check_autopause()
+                self.current_time.set(t)
+
+                self.last_poll_time = time.time()
 
-        reactor.callLater(.05, self.pollStatus)
+            self.check_autopause()
+        finally:
+            reactor.callLater(.05, self.pollStatus)
 
     def set_total_time(self, song_path):
         # currently only good for .wav