banshee r4909 - in trunk/banshee: . src/Libraries/Lastfm/Lastfm



Author: gburt
Date: Sun Jan 11 19:30:18 2009
New Revision: 4909
URL: http://svn.gnome.org/viewvc/banshee?rev=4909&view=rev

Log:
2009-01-11  Gabriel Burt  <gabriel burt gmail com>

	* src/Libraries/Lastfm/Lastfm/AudioscrobblerConnection.cs: Fix recently
	introduced bug that hung Banshee when Last.fm submitted Now Playing
	information (BNC #465215) 



Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/src/Libraries/Lastfm/Lastfm/AudioscrobblerConnection.cs

Modified: trunk/banshee/src/Libraries/Lastfm/Lastfm/AudioscrobblerConnection.cs
==============================================================================
--- trunk/banshee/src/Libraries/Lastfm/Lastfm/AudioscrobblerConnection.cs	(original)
+++ trunk/banshee/src/Libraries/Lastfm/Lastfm/AudioscrobblerConnection.cs	Sun Jan 11 19:30:18 2009
@@ -544,20 +544,13 @@
                 now_playing_post.UserAgent = LastfmCore.UserAgent;
                 now_playing_post.Method = "POST";
                 now_playing_post.ContentType = "application/x-www-form-urlencoded";
-                
-                ASCIIEncoding encoding = new ASCIIEncoding ();
-                byte[] data_bytes = encoding.GetBytes (data);
-                now_playing_post.ContentLength = data_bytes.Length;
-                Stream request_stream = now_playing_post.GetRequestStream ();
-                request_stream.Write (data_bytes, 0, data_bytes.Length);
-                request_stream.Close ();
 
                 if (state == State.Idle) {
                     // Don't actually POST it until we're idle (that is, we
                     // probably have stuff queued which will reset the Now
                     // Playing if we send them first).
-                    now_playing_post.BeginGetResponse (NowPlayingGetResponse, null);
                     now_playing_started = true;
+                    now_playing_post.BeginGetRequestStream (NowPlayingGetRequestStream, data);
                 }
             } catch (Exception ex) {
                 Log.Warning ("Audioscrobbler NowPlaying failed",
@@ -568,6 +561,22 @@
             }
         }
 
+        private void NowPlayingGetRequestStream (IAsyncResult ar)
+        {
+            try {
+                string data = ar.AsyncState as string;
+                ASCIIEncoding encoding = new ASCIIEncoding ();
+                byte[] data_bytes = encoding.GetBytes (data);
+                Stream request_stream = now_playing_post.EndGetRequestStream (ar);
+                request_stream.Write (data_bytes, 0, data_bytes.Length);
+                request_stream.Close ();
+
+                now_playing_post.BeginGetResponse (NowPlayingGetResponse, null);
+            } catch (Exception e) {
+                Log.Exception (e);
+            }
+        }
+
         private void NowPlayingGetResponse (IAsyncResult ar)
         {
             try {



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