Changeset - e841bea500c3
[Not reviewed]
default
0 1 0
drewp@bigasterisk.com - 20 years ago 2005-06-18 15:41:28
drewp@bigasterisk.com
guard against some errors when mpd is playing other music
1 file changed with 32 insertions and 31 deletions:
0 comments (0 inline, 0 general)
bin/ascoltami
Show inline comments
 
@@ -111,43 +111,44 @@ class Player:
 
        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
0 comments (0 inline, 0 general)