Re: [Banshee-List] Patch: delay now-playing submission



Scratch that. I didn't like how expensive that if statement was
in PlayerEngineEvent.Iterate so I have moved the brunt of it back to
PlayerEngineEvent.StartOfStream.


--
Index:
src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Audioscrobbler/AudioscrobblerService.cs
===================================================================
---
src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Audioscrobbler/AudioscrobblerService.cs	(revision 3371)
+++
src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Audioscrobbler/AudioscrobblerService.cs	(working copy)
@@ -63,6 +63,8 @@
         private Account account;
         
         private bool queued; /* if current_track has been queued */
+        private bool nowplaying_queued; /* if current_track has been
queued as NowPlaying */
+        private bool nowplaying_watch; /* if NowPlaying should be
watched for */
         
         private DateTime song_start_time;
         private TrackInfo last_track;
@@ -227,16 +229,18 @@
                     st.Reset ();
                     song_start_time = DateTime.Now;
                     last_track =
ServiceManager.PlayerEngine.CurrentTrack;
-                    queued = false;
-
-                    // Queue as now playing
+                    queued = false;                        
+                    nowplaying_queued = false;
+                        
+                    // check if we should have Iterate: watch and
submit NowPlaying
                     if (last_track != null &&
last_track.Duration.TotalSeconds > 30 &&
                         (actions["AudioscrobblerEnableAction"] as
ToggleAction).Active) {
                         
-                        connection.NowPlaying (last_track.ArtistName,
last_track.TrackTitle,
-                            last_track.AlbumTitle,
last_track.Duration.TotalSeconds, last_track.TrackNumber);
+                        nowplaying_watch = true;
+                    } else {
+                        nowplaying_watch = false;
                     }
-                    
+                                                
                     break;
                 
                 case PlayerEngineEvent.Seek:
@@ -245,6 +249,16 @@
                 
                 case PlayerEngineEvent.Iterate:
                     st.IncreasePosition ();
+                        
+                    // see if we should submit NowPlaying yet
+                    if (nowplaying_watch &&
ServiceManager.PlayerEngine.Position > 4000 &&
+                        !nowplaying_queued) {
+                      
+                        connection.NowPlaying (last_track.ArtistName,
last_track.TrackTitle,
+                            last_track.AlbumTitle,
last_track.Duration.TotalSeconds, last_track.TrackNumber);
+                        
+                        nowplaying_queued = true;
+                    }  
                     break;
                 
                 case PlayerEngineEvent.EndOfStream:


Index: src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Audioscrobbler/AudioscrobblerService.cs
===================================================================
--- src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Audioscrobbler/AudioscrobblerService.cs	(revision 3371)
+++ src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Audioscrobbler/AudioscrobblerService.cs	(working copy)
@@ -63,6 +63,8 @@
         private Account account;
         
         private bool queued; /* if current_track has been queued */
+        private bool nowplaying_queued; /* if current_track has been queued as NowPlaying */
+        private bool nowplaying_watch; /* if NowPlaying should be watched for */
         
         private DateTime song_start_time;
         private TrackInfo last_track;
@@ -227,16 +229,18 @@
                     st.Reset ();
                     song_start_time = DateTime.Now;
                     last_track = ServiceManager.PlayerEngine.CurrentTrack;
-                    queued = false;
-
-                    // Queue as now playing
+                    queued = false;                        
+                    nowplaying_queued = false;
+                        
+                    // check if we should have Iterate: watch and submit NowPlaying
                     if (last_track != null && last_track.Duration.TotalSeconds > 30 &&
                         (actions["AudioscrobblerEnableAction"] as ToggleAction).Active) {
                         
-                        connection.NowPlaying (last_track.ArtistName, last_track.TrackTitle,
-                            last_track.AlbumTitle, last_track.Duration.TotalSeconds, last_track.TrackNumber);
+                        nowplaying_watch = true;
+                    } else {
+                        nowplaying_watch = false;
                     }
-                    
+                                                
                     break;
                 
                 case PlayerEngineEvent.Seek:
@@ -245,6 +249,16 @@
                 
                 case PlayerEngineEvent.Iterate:
                     st.IncreasePosition ();
+                        
+                    // see if we should submit NowPlaying yet
+                    if (nowplaying_watch &&  ServiceManager.PlayerEngine.Position > 4000 &&
+                        !nowplaying_queued) {
+                      
+                        connection.NowPlaying (last_track.ArtistName, last_track.TrackTitle,
+                            last_track.AlbumTitle, last_track.Duration.TotalSeconds, last_track.TrackNumber);
+                        
+                        nowplaying_queued = true;
+                    }  
                     break;
                 
                 case PlayerEngineEvent.EndOfStream:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]