=== modified file 'libbanshee/banshee-player-pipeline.c'
--- libbanshee/banshee-player-pipeline.c	2009-06-08 22:17:54 +0000
+++ libbanshee/banshee-player-pipeline.c	2009-09-29 08:41:19 +0000
@@ -62,6 +62,38 @@
     }
 }
 
+void bp_try_set_audiosink_buffer (GstElement *element, guint64 *buffer_len)
+{
+    if (g_object_class_find_property (G_OBJECT_GET_CLASS (element), "buffer-time")) {
+        g_object_set (G_OBJECT (element), "buffer-time", *buffer_len, NULL);
+    }
+    gst_object_unref (G_OBJECT (element));
+}
+
+static void
+bp_set_audiosink_buffer_length (BansheePlayer *player, guint64 buffer_len)
+{
+    GstIterator *sink_iterator;
+    GstIteratorResult iter_result;
+    GstElement *audiosink;
+    
+    g_return_if_fail (IS_BANSHEE_PLAYER (player));
+    audiosink = player->audiosink;
+    // If we've directly selected alsasink or directsoundsink then we'll have a
+    // buffer-time property on audiosink.  If so, just set this and return.
+    if (g_object_class_find_property (G_OBJECT_GET_CLASS (audiosink), "buffer-time")) {
+        g_object_set (G_OBJECT (audiosink), "buffer-time", buffer_len, NULL);
+        return;
+    }
+    // If we've selected an auto audio sink, then the real audio sink is a child of the bin.
+    sink_iterator = gst_bin_iterate_recurse (GST_BIN (audiosink));
+    iter_result = gst_iterator_foreach (sink_iterator, (GFunc)&bp_try_set_audiosink_buffer, &buffer_len);
+    if (iter_result == GST_ITERATOR_ERROR) {
+        bp_debug ("Failed to set audio buffer length: failed to find sink");
+    }
+    gst_iterator_free (sink_iterator);
+}
+
 static gboolean
 bp_pipeline_bus_callback (GstBus *bus, GstMessage *message, gpointer userdata)
 {
@@ -81,7 +113,16 @@
         case GST_MESSAGE_STATE_CHANGED: {
             GstState old, new, pending;
             gst_message_parse_state_changed (message, &old, &new, &pending);
-            
+
+            if (new == GST_STATE_READY) {            
+                // Explicitly set the buffer length.
+                // We need to know the buffer length so that we can emit a fake track-changed signal at something
+                // approximating the right time, at least until playbin2 can do this for us.  
+                // The easiest way to do this is to set the buffer to a known length.
+                // 
+                // gconfaudiosink only has a real audiosink in it once it's made a transition to READY.
+                bp_set_audiosink_buffer_length (player, BP_BUFFER_LEN_MICROSECONDS);
+            }
             _bp_missing_elements_handle_state_changed (player, old, new);
             _bp_replaygain_handle_state_changed (player, old, new, pending);
             
@@ -171,6 +212,31 @@
     return TRUE;
 }
 
+static gboolean 
+bp_next_track_starting (gpointer player)
+{
+    g_return_val_if_fail (IS_BANSHEE_PLAYER (player), FALSE);
+    
+    bp_debug ("[gapless] Triggering track-change signal");
+    if (((BansheePlayer *)player)->next_track_starting_cb != NULL) {
+        ((BansheePlayer *)player)->next_track_starting_cb (player);
+    }
+    ((BansheePlayer *)player)->timeout_id = 0;
+    return FALSE;
+}
+
+static void bp_about_to_finish_callback (GstElement *playbin, BansheePlayer *player)
+{
+    g_return_if_fail (IS_BANSHEE_PLAYER (player));
+    // Playbin2 doesn't (yet) have any way to notify us when the current track has actually finished playing on the
+    // hardware.  Fake this for now by adding a timer with length equal to the hardware buffer.
+    player->timeout_id = g_timeout_add (((guint64)BP_BUFFER_LEN_MICROSECONDS) / 1000, &bp_next_track_starting, player);
+    
+    if (player->about_to_finish_cb != NULL) {
+        player->about_to_finish_cb (player);
+    }
+}
+
 // ---------------------------------------------------------------------------
 // Internal Functions
 // ---------------------------------------------------------------------------
@@ -180,7 +246,6 @@
 {
     GstBus *bus;
     GstPad *teepad;
-    GstElement *audiosink;
     GstElement *audiosinkqueue;
     GstElement *eq_audioconvert = NULL;
     GstElement *eq_audioconvert2 = NULL;
@@ -189,31 +254,35 @@
     
     // Playbin is the core element that handles autoplugging (finding the right
     // source and decoder elements) based on source URI and stream content
-    player->playbin = gst_element_factory_make ("playbin", "playbin");
+    player->playbin = gst_element_factory_make ("playbin2", "playbin");
     g_return_val_if_fail (player->playbin != NULL, FALSE);
+    
+    // Connect a proxy about-to-finish callback that will generate a next-track-starting callback.
+    // This can be removed once playbin2 generates its own next-track signal.
+    g_signal_connect (player->playbin, "about-to-finish", G_CALLBACK (bp_about_to_finish_callback), player);
 
     // Try to find an audio sink, prefer gconf, which typically is set to auto these days,
     // fall back on auto, which should work on windows, and as a last ditch, try alsa
-    audiosink = gst_element_factory_make ("gconfaudiosink", "audiosink");
-    if (audiosink == NULL) {
-        audiosink = gst_element_factory_make ("directsoundsink", "audiosink");
-        if (audiosink != NULL) {
-            g_object_set (G_OBJECT (audiosink), "volume", 1.0, NULL);
+    player->audiosink = gst_element_factory_make ("gconfaudiosink", "audiosink");
+    if (player->audiosink == NULL) {
+        player->audiosink = gst_element_factory_make ("directsoundsink", "audiosink");
+        if (player->audiosink != NULL) {
+            g_object_set (G_OBJECT (player->audiosink), "volume", 1.0, NULL);
         } else {
-            audiosink = gst_element_factory_make ("autoaudiosink", "audiosink");
-            if (audiosink == NULL) {
-                audiosink = gst_element_factory_make ("alsasink", "audiosink");
+            player->audiosink = gst_element_factory_make ("autoaudiosink", "audiosink");
+            if (player->audiosink == NULL) {
+                player->audiosink = gst_element_factory_make ("alsasink", "audiosink");
             }
         }
     }
     
-    g_return_val_if_fail (audiosink != NULL, FALSE);
+    g_return_val_if_fail (player->audiosink != NULL, FALSE);
         
     // Set the profile to "music and movies" (gst-plugins-good 0.10.3)
-    if (g_object_class_find_property (G_OBJECT_GET_CLASS (audiosink), "profile")) {
-        g_object_set (G_OBJECT (audiosink), "profile", 1, NULL);
+    if (g_object_class_find_property (G_OBJECT_GET_CLASS (player->audiosink), "profile")) {
+        g_object_set (G_OBJECT (player->audiosink), "profile", 1, NULL);
     }
-    
+        
     // Create a custom audio sink bin that will hold the real primary sink
     player->audiobin = gst_bin_new ("audiobin");
     g_return_val_if_fail (player->audiobin != NULL, FALSE);
@@ -244,7 +313,7 @@
     }
     
     gst_bin_add (GST_BIN (player->audiobin), audiosinkqueue);
-    gst_bin_add (GST_BIN (player->audiobin), audiosink);
+    gst_bin_add (GST_BIN (player->audiobin), player->audiosink);
    
     // Ghost pad the audio bin so audio is passed from the bin into the tee
     teepad = gst_element_get_pad (player->audiotee, "sink");
@@ -255,10 +324,10 @@
     if (player->equalizer != NULL) {
         // link in equalizer, preamp and audioconvert.
         gst_element_link_many (audiosinkqueue, eq_audioconvert, player->preamp, 
-            player->equalizer, eq_audioconvert2, audiosink, NULL);
+            player->equalizer, eq_audioconvert2, player->audiosink, NULL);
     } else {
         // link the queue with the real audio sink
-        gst_element_link (audiosinkqueue, audiosink);
+        gst_element_link (audiosinkqueue, player->audiosink);
     }
     
     _bp_vis_pipeline_setup (player);

=== modified file 'libbanshee/banshee-player-private.h'
--- libbanshee/banshee-player-private.h	2009-05-19 22:08:23 +0000
+++ libbanshee/banshee-player-private.h	2009-09-29 02:43:39 +0000
@@ -68,6 +68,8 @@
 #define bp_debug(x...) banshee_log_debug ("player", x)
 #endif
 
+#define BP_BUFFER_LEN_MICROSECONDS 1000000
+
 typedef struct BansheePlayer BansheePlayer;
 
 typedef void (* BansheePlayerEosCallback)          (BansheePlayer *player);
@@ -79,6 +81,8 @@
 typedef void (* BansheePlayerBufferingCallback)    (BansheePlayer *player, gint buffering_progress);
 typedef void (* BansheePlayerTagFoundCallback)     (BansheePlayer *player, const gchar *tag, const GValue *value);
 typedef void (* BansheePlayerVisDataCallback)      (BansheePlayer *player, gint channels, gint samples, gfloat *data, gint bands, gfloat *spectrum);
+typedef void (* BansheePlayerNextTrackStartingCallback)     (BansheePlayer *player);
+typedef void (* BansheePlayerAboutToFinishCallback)         (BansheePlayer *player);
 typedef GstElement * (* BansheePlayerVideoPipelineSetupCallback) (BansheePlayer *player, GstBus *bus);
 
 typedef enum {
@@ -96,10 +100,13 @@
     BansheePlayerBufferingCallback buffering_cb;
     BansheePlayerTagFoundCallback tag_found_cb;
     BansheePlayerVisDataCallback vis_data_cb;
+    BansheePlayerNextTrackStartingCallback next_track_starting_cb;
+    BansheePlayerAboutToFinishCallback about_to_finish_cb;
     BansheePlayerVideoPipelineSetupCallback video_pipeline_setup_cb;
 
     // Pipeline Elements
     GstElement *playbin;
+    GstElement *audiosink;
     GstElement *audiotee;
     GstElement *audiobin;
     GstElement *equalizer;
@@ -156,6 +163,8 @@
     gdouble album_peak;
     gdouble track_gain;
     gdouble track_peak;
+    
+    guint timeout_id;
 };
 
 #endif /* _BANSHEE_PLAYER_PRIVATE_H */

=== modified file 'libbanshee/banshee-player.c'
--- libbanshee/banshee-player.c	2009-05-15 22:06:13 +0000
+++ libbanshee/banshee-player.c	2009-09-29 02:43:39 +0000
@@ -180,6 +180,11 @@
         state = GST_STATE_NULL;
     }
     
+    if (player->timeout_id != 0) {
+        g_source_remove (player->timeout_id);
+        player->timeout_id = 0;
+    }
+    
     bp_debug ("bp_stop: setting state to %s", 
         state == GST_STATE_NULL ? "GST_STATE_NULL" : "GST_STATE_PAUSED");
     
@@ -195,10 +200,24 @@
 P_INVOKE void
 bp_play (BansheePlayer *player)
 {
+    g_return_if_fail (IS_BANSHEE_PLAYER (player));
+    if (player->timeout_id != 0) {
+        g_source_remove (player->timeout_id);
+        player->timeout_id = 0;
+    }
     bp_pipeline_set_state (player, GST_STATE_PLAYING);
 }
 
 P_INVOKE gboolean
+bp_set_next_track (BansheePlayer *player, const gchar *uri)
+{
+    g_return_val_if_fail (IS_BANSHEE_PLAYER (player), FALSE);
+    g_return_val_if_fail (player->playbin != NULL, FALSE);
+    g_object_set (G_OBJECT (player->playbin), "uri", uri, NULL);
+    return TRUE;
+}
+
+P_INVOKE gboolean
 bp_set_position (BansheePlayer *player, guint64 time_ms)
 {
     g_return_val_if_fail (IS_BANSHEE_PLAYER (player), FALSE);
@@ -348,3 +367,15 @@
     *resource = GST_RESOURCE_ERROR;
     *stream = GST_STREAM_ERROR;
 }
+
+P_INVOKE void
+bp_set_next_track_starting_callback (BansheePlayer *player, BansheePlayerNextTrackStartingCallback cb)
+{
+    SET_CALLBACK (next_track_starting_cb);
+}
+
+P_INVOKE void
+bp_set_about_to_finish_callback (BansheePlayer *player, BansheePlayerAboutToFinishCallback cb)
+{
+    SET_CALLBACK (about_to_finish_cb);
+}

=== modified file 'src/Backends/Banshee.GStreamer/Banshee.GStreamer/PlayerEngine.cs'
--- src/Backends/Banshee.GStreamer/Banshee.GStreamer/PlayerEngine.cs	2009-09-11 21:31:27 +0000
+++ src/Backends/Banshee.GStreamer/Banshee.GStreamer/PlayerEngine.cs	2009-09-29 02:43:39 +0000
@@ -29,6 +29,7 @@
 using System;
 using System.Collections;
 using System.Runtime.InteropServices;
+using System.Threading;
 using Mono.Unix;
 using Hyena;
 using Hyena.Data;
@@ -57,6 +58,8 @@
     internal delegate void BansheePlayerIterateCallback (IntPtr player);
     internal delegate void BansheePlayerBufferingCallback (IntPtr player, int buffering_progress);
     internal delegate void BansheePlayerVisDataCallback (IntPtr player, int channels, int samples, IntPtr data, int bands, IntPtr spectrum);
+    internal delegate void BansheePlayerNextTrackStartingCallback (IntPtr player);
+    internal delegate void BansheePlayerAboutToFinishCallback (IntPtr player);
     internal delegate IntPtr VideoPipelineSetupHandler (IntPtr player, IntPtr bus);
 
     internal delegate void GstTaggerTagFoundCallback (IntPtr player, string tagName, ref GLib.Value value);
@@ -79,10 +82,15 @@
         private BansheePlayerVisDataCallback vis_data_callback;
         private VideoPipelineSetupHandler video_pipeline_setup_callback;
         private GstTaggerTagFoundCallback tag_found_callback;
+        private BansheePlayerNextTrackStartingCallback next_track_starting_callback;
+        private BansheePlayerAboutToFinishCallback about_to_finish_callback;
         
         private bool buffering_finished;
         private int pending_volume = -1;
         private bool xid_is_set = false;
+
+        private bool GaplessEnabled;
+        private EventWaitHandle next_track_set;
         
         private event VisualizationDataHandler data_available = null;
         public event VisualizationDataHandler DataAvailable {
@@ -135,14 +143,19 @@
             vis_data_callback = new BansheePlayerVisDataCallback (OnVisualizationData);
             video_pipeline_setup_callback = new VideoPipelineSetupHandler (OnVideoPipelineSetup);
             tag_found_callback = new GstTaggerTagFoundCallback (OnTagFound);
-            
+            next_track_starting_callback = new BansheePlayerNextTrackStartingCallback (OnNextTrackStarting);
+            about_to_finish_callback = new BansheePlayerAboutToFinishCallback (OnAboutToFinish);
+
             bp_set_eos_callback (handle, eos_callback);
             bp_set_iterate_callback (handle, iterate_callback);
             bp_set_error_callback (handle, error_callback);
             bp_set_state_changed_callback (handle, state_changed_callback);
             bp_set_buffering_callback (handle, buffering_callback);
             bp_set_tag_found_callback (handle, tag_found_callback);
+            bp_set_next_track_starting_callback (handle, next_track_starting_callback);
             bp_set_video_pipeline_setup_callback (handle, video_pipeline_setup_callback);
+
+            next_track_set = new EventWaitHandle (false, EventResetMode.AutoReset);
         }
         
         protected override void Initialize ()
@@ -161,6 +174,11 @@
             
             InstallPreferences ();
             ReplayGainEnabled = ReplayGainEnabledSchema.Get ();
+            GaplessEnabled = GaplessEnabledSchema.Get ();
+
+            if (GaplessEnabled) {
+                bp_set_about_to_finish_callback (handle, about_to_finish_callback);
+            }
         }
         
         public override void Dispose ()
@@ -209,6 +227,22 @@
         {
             bp_pause (handle);
         }
+
+        public override void SetNextTrackUri (SafeUri uri)
+        {
+            // If there isn't a next track for us, release the block on the about-to-finish callback.
+            if (uri == null) {
+                next_track_set.Set ();
+                return;
+            }            
+            IntPtr uri_ptr = GLib.Marshaller.StringToPtrGStrdup (uri.AbsoluteUri);
+            try {
+                bp_set_next_track (handle, uri_ptr);
+            } finally {
+                GLib.Marshaller.Free (uri_ptr);
+            }
+            next_track_set.Set ();
+        }
         
         public override void VideoExpose (IntPtr window, bool direct)
         {
@@ -230,7 +264,38 @@
         {
             Close (false);
             OnEventChanged (PlayerEvent.EndOfStream);
-        }
+            OnEventChanged (PlayerEvent.RequestNexttrack);
+        }
+
+        private void OnNextTrackStarting (IntPtr player)
+        {
+            if (GaplessEnabled) {
+                OnEventChanged (PlayerEvent.EndOfStream);
+                OnEventChanged (PlayerEvent.StartOfStream);
+            }
+        }
+
+        private void OnAboutToFinish (IntPtr player)
+        {
+            /*
+             * This is needed to make Shuffle-by-* work.
+             * Shuffle-by-* uses the LastPlayed field to determine what track in the grouping to play next.
+             * Therefore, we need to update this before requesting the next track.
+             *
+             * This will be overridden by IncrementLastPlayed () called by 
+             * PlaybackControllerService's EndOfStream handler.
+             */
+            CurrentTrack.LastPlayed = DateTime.Now;
+            CurrentTrack.Save ();
+            
+            OnEventChanged (PlayerEvent.RequestNexttrack);
+            // Gapless playback with Playbin2 requires that the about-to-finish callback does not return until
+            // the next uri has been set.  Block here for a second or until the RequestNextTrack event has 
+            // finished triggering.
+            if (!next_track_set.WaitOne (1000, false)) {
+                Log.Debug ("[Gapless] Timed out while waiting for next_track_set to be raised");
+            }
+        }       
         
         private void OnIterate (IntPtr player)
         {
@@ -543,6 +608,7 @@
 #region Preferences
 
         private PreferenceBase replaygain_preference;
+        private PreferenceBase gapless_preference;
 
         private void InstallPreferences ()
         {
@@ -556,6 +622,11 @@
                 Catalog.GetString ("For tracks that have ReplayGain data, automatically scale (normalize) playback volume."),
                 delegate { ReplayGainEnabled = ReplayGainEnabledSchema.Get (); }
             ));
+            gapless_preference = service["general"]["misc"].Add (new SchemaPreference<bool> (GaplessEnabledSchema,
+                Catalog.GetString ("Enable _gapless playback (EXPERIMENTAL)"),
+                Catalog.GetString ("Eliminate the small playback gap on track change.  Useful for concept albums & classical music."),
+                delegate { GaplessEnabled = GaplessEnabledSchema.Get (); }
+            ));                            
         }
         
         private void UninstallPreferences ()
@@ -566,7 +637,9 @@
             }
             
             service["general"]["misc"].Remove (replaygain_preference);
+            service["general"]["misc"].Remove (gapless_preference);
             replaygain_preference = null;
+            gapless_preference = null;
         }
         
         public static readonly SchemaEntry<bool> ReplayGainEnabledSchema = new SchemaEntry<bool> (
@@ -576,6 +649,14 @@
             "If ReplayGain data is present on tracks when playing, allow volume scaling"
         );
 
+        public static readonly SchemaEntry<bool> GaplessEnabledSchema = new SchemaEntry<bool> (
+            "player_engine", "gapless_playback_enabled",
+            false,
+            "Enable gapless playback (EXPERIMENTAL)",
+            "Eliminate the small playback gap on track change.  Useful for concept albums & classical music.  EXPERIMENTAL"
+        );
+                                                                                              
+
 #endregion
         
         [DllImport ("libbanshee.dll")]
@@ -615,6 +696,14 @@
         [DllImport ("libbanshee.dll")]
         private static extern void bp_set_tag_found_callback (HandleRef player,
             GstTaggerTagFoundCallback cb);
+
+        [DllImport ("libbanshee")]
+        private static extern void bp_set_next_track_starting_callback (HandleRef player,
+            BansheePlayerNextTrackStartingCallback cb);
+
+        [DllImport ("libbanshee.dll")]
+        private static extern void bp_set_about_to_finish_callback (HandleRef player,
+            BansheePlayerAboutToFinishCallback cb);
         
         [DllImport ("libbanshee.dll")]
         private static extern bool bp_open (HandleRef player, IntPtr uri);
@@ -629,6 +718,9 @@
         private static extern void bp_play (HandleRef player);
         
         [DllImport ("libbanshee.dll")]
+        private static extern bool bp_set_next_track (HandleRef player, IntPtr uri);
+
+        [DllImport ("libbanshee.dll")]
         private static extern void bp_set_volume (HandleRef player, double volume);
         
         [DllImport("libbanshee.dll")]

=== modified file 'src/Core/Banshee.Services/Banshee.MediaEngine/PlayerEngine.cs'
--- src/Core/Banshee.Services/Banshee.MediaEngine/PlayerEngine.cs	2009-05-27 01:07:56 +0000
+++ src/Core/Banshee.Services/Banshee.MediaEngine/PlayerEngine.cs	2009-09-29 02:43:39 +0000
@@ -47,6 +47,8 @@
         
         private TrackInfo current_track;
         private SafeUri current_uri;
+        private TrackInfo pending_track;
+        private SafeUri pending_uri;
         private PlayerState current_state = PlayerState.NotReady;
         private PlayerState last_state = PlayerState.NotReady;
         
@@ -98,6 +100,40 @@
             HandleOpen (uri);
         }
 
+        public void SetNextTrack (TrackInfo track)
+        {
+            pending_track = track;
+            pending_uri = track.Uri;
+
+            HandleNextTrack (pending_uri);
+        }
+
+        public void SetNextTrack (SafeUri uri)
+        {
+            pending_uri = uri;
+            pending_track = new UnknownTrackInfo (uri);
+
+            HandleNextTrack (uri);
+        }
+
+        private void HandleNextTrack (SafeUri uri)
+        {
+            if (current_state != PlayerState.Playing) {
+                // Pre-buffering the next track only makes sense when we're currently playing
+                // Instead, just open.
+                HandleOpen (uri);
+                Play ();
+                return;
+            }
+
+            try {
+                // Setting the next track doesn't change the player state.
+                SetNextTrackUri (uri);
+            } catch (Exception e) {
+                Log.Exception ("Failed to pre-buffer next track", e);
+            }
+        }
+
         private void HandleOpen (SafeUri uri)
         {
             if (current_state != PlayerState.Idle && current_state != PlayerState.NotReady && current_state != PlayerState.Contacting) {
@@ -117,6 +153,13 @@
 
         public abstract void Pause ();
 
+        public virtual void SetNextTrackUri (SafeUri uri)
+        {
+            // Opening files on SetNextTrack is a sane default behaviour.
+            // This only wants to be overridden if the PlayerEngine sends out RequestNextTrack signals before EoS
+            OpenUri (uri);
+        }
+
         public virtual void VideoExpose (IntPtr displayContext, bool direct)
         {
             throw new NotImplementedException ("Engine must implement VideoExpose since this method only gets called when SupportsVideo is true");
@@ -163,6 +206,13 @@
         
         protected virtual void OnEventChanged (PlayerEventArgs args)
         {
+            if (args.Event == PlayerEvent.StartOfStream && pending_track != null) {
+                Log.DebugFormat ("OnEventChanged called with StartOfStream.  Replacing current_track: \"{0}\" with pending_track: \"{1}\"", current_track.DisplayTrackTitle, pending_track.DisplayTrackTitle);
+                current_track = pending_track;
+                current_uri = pending_uri;
+                pending_track = null;
+                pending_uri = null;
+            }
             if (ThreadAssist.InMainThread) {
                 RaiseEventChanged (args);
             } else {

=== modified file 'src/Core/Banshee.Services/Banshee.MediaEngine/PlayerEngineService.cs'
--- src/Core/Banshee.Services/Banshee.MediaEngine/PlayerEngineService.cs	2009-06-29 20:00:54 +0000
+++ src/Core/Banshee.Services/Banshee.MediaEngine/PlayerEngineService.cs	2009-09-29 02:43:39 +0000
@@ -245,6 +245,10 @@
                     CurrentTrack.SavePlaybackError (StreamPlaybackError.None);
                 }
             }
+
+            if (args.Event == PlayerEvent.StartOfStream) {
+                incremented_last_played = false;
+            }
             
             RaiseEvent (args);
             
@@ -302,7 +306,40 @@
         {
             OpenCheck (new SafeUri (uri));
         }
-        
+
+
+        public void SetNextTrack (TrackInfo track)
+        {
+            if (active_engine != FindSupportingEngine (track.Uri)) {
+                if (active_engine.CurrentState == PlayerState.Playing) {
+                    // If we're playing and the current engine can't handle the next track then treat this as setting
+                    // no next track for the engine, since it's not going to receive this next track.
+                    track = null;
+                } else {
+                    // If we're not playing, then switch engines and Open
+                    SwitchToEngine (FindSupportingEngine (track.Uri));
+                    CheckPending ();
+                }
+            }
+            active_engine.SetNextTrack (track);
+        }
+
+        public void SetNextTrack (SafeUri uri)
+        {
+            if (active_engine != FindSupportingEngine (uri)) {
+                if (active_engine.CurrentState == PlayerState.Playing) {
+                    // If we're playing and the current engine can't handle the next track then treat this as setting
+                    // no next track for the engine, since it's not going to receive this next track.
+                    uri = null;
+                } else {
+                    // If we're not playing, then switch engines and Open
+                    SwitchToEngine (FindSupportingEngine (uri));
+                    CheckPending ();
+                }
+            }
+            active_engine.SetNextTrack (uri);
+        }
+
         public void OpenPlay (TrackInfo track)
         {
             OpenPlay (track, true);
@@ -349,17 +386,14 @@
                 return;
             }
 
-            IncrementLastPlayed ();
-            
-            FindSupportingEngine (uri);
+            PlayerEngine supportingEngine = FindSupportingEngine (uri);
+            SwitchToEngine (supportingEngine);
             CheckPending ();
             
             if (track != null) {
                 active_engine.Open (track);
-                incremented_last_played = false;
             } else if (uri != null) {
                 active_engine.Open (uri);
-                incremented_last_played = false;
             }
 
             if (play) {
@@ -381,34 +415,39 @@
             }
         }
         
-        private void FindSupportingEngine (SafeUri uri)
+        private PlayerEngine FindSupportingEngine (SafeUri uri)
         {
             foreach (PlayerEngine engine in engines) {
                 foreach (string extension in engine.ExplicitDecoderCapabilities) {
                     if (!uri.AbsoluteUri.EndsWith (extension)) {
                         continue;
-                    } else if (active_engine != engine) {
-                        Close ();
-                        pending_engine = engine;
-                        Log.DebugFormat ("Switching engine to: {0}", engine.GetType ());
                     }
-                    return;
+                    return engine;
                 }
             }
         
             foreach (PlayerEngine engine in engines) {
                 foreach (string scheme in engine.SourceCapabilities) {
                     bool supported = scheme == uri.Scheme;
-                    if (supported && active_engine != engine) {
-                        Close ();
-                        pending_engine = engine;
-                        Log.DebugFormat ("Switching engine to: {0}", engine.GetType ());
-                        return;
-                    } else if (supported) {
-                        return;
+                    if (supported) {
+                        return engine;
                     }
                 }
             }
+            // If none of our engines support this URI, return the currently active one.
+            // There doesn't seem to be anything better to do.
+            return active_engine;
+        }
+
+        private bool SwitchToEngine (PlayerEngine switchTo)
+        {
+            if (active_engine != switchTo) {
+                Close ();
+                pending_engine = switchTo;
+                Log.DebugFormat ("Switching engine to: {0}", switchTo.GetType ());
+                return true;
+            }
+            return false;
         }
         
         public void Close ()
@@ -644,7 +683,8 @@
             | PlayerEvent.Error
             | PlayerEvent.Volume
             | PlayerEvent.Metadata
-            | PlayerEvent.TrackInfoUpdated;
+            | PlayerEvent.TrackInfoUpdated
+            | PlayerEvent.RequestNexttrack;
         
         private const PlayerEvent event_default_mask = event_all_mask & ~PlayerEvent.Iterate;
         

=== modified file 'src/Core/Banshee.Services/Banshee.MediaEngine/PlayerEvent.cs'
--- src/Core/Banshee.Services/Banshee.MediaEngine/PlayerEvent.cs	2008-05-04 21:42:09 +0000
+++ src/Core/Banshee.Services/Banshee.MediaEngine/PlayerEvent.cs	2009-09-29 02:43:39 +0000
@@ -108,7 +108,8 @@
         Error = 64,
         Volume = 128,
         Metadata = 256,
-        TrackInfoUpdated = 512
+        TrackInfoUpdated = 512,
+        RequestNexttrack = 1024
     }
     
     public enum PlayerState 

=== modified file 'src/Core/Banshee.Services/Banshee.PlaybackController/IBasicPlaybackController.cs'
--- src/Core/Banshee.Services/Banshee.PlaybackController/IBasicPlaybackController.cs	2008-10-02 00:36:15 +0000
+++ src/Core/Banshee.Services/Banshee.PlaybackController/IBasicPlaybackController.cs	2009-09-29 02:43:39 +0000
@@ -31,7 +31,7 @@
     public interface IBasicPlaybackController
     {
         bool First ();
-        bool Next (bool restart);
+        bool Next (bool restart, bool userRequested);
         bool Previous (bool restart);
     }
 }

=== modified file 'src/Core/Banshee.Services/Banshee.PlaybackController/PlaybackControllerService.cs'
--- src/Core/Banshee.Services/Banshee.PlaybackController/PlaybackControllerService.cs	2009-06-13 00:26:27 +0000
+++ src/Core/Banshee.Services/Banshee.PlaybackController/PlaybackControllerService.cs	2009-09-29 02:43:39 +0000
@@ -89,7 +89,8 @@
             
             player_engine = ServiceManager.PlayerEngine;
             player_engine.PlayWhenIdleRequest += OnPlayerEnginePlayWhenIdleRequest;
-            player_engine.ConnectEvent (OnPlayerEvent, 
+            player_engine.ConnectEvent (OnPlayerEvent,
+                PlayerEvent.RequestNexttrack |
                 PlayerEvent.EndOfStream | 
                 PlayerEvent.StartOfStream |
                 PlayerEvent.StateChange |
@@ -164,6 +165,9 @@
                         transition_track_started = true;
                     }
                     break;
+                case PlayerEvent.RequestNexttrack:
+                    RequestTrackHandler ();
+                    break;
             }       
         }
         
@@ -174,15 +178,21 @@
                 error_transition_id = 0;
             }
         }
-        
+
         private bool EosTransition ()
         {
+            player_engine.IncrementLastPlayed ();
+            return true;
+        }
+        
+        private bool RequestTrackHandler ()
+        {
             if (!StopWhenFinished) {
                 if (RepeatMode == PlaybackRepeatMode.RepeatSingle) {
                     QueuePlayTrack ();
                 } else {
                     last_was_skipped = false;
-                    Next ();
+                    Next (RepeatMode == PlaybackRepeatMode.RepeatSingle, false);
                 }
             } else {
                 OnStopped ();
@@ -211,21 +221,28 @@
         
         public void Next ()
         {
-            Next (RepeatMode == PlaybackRepeatMode.RepeatAll);
+            Next (RepeatMode == PlaybackRepeatMode.RepeatAll, true);
         }
-        
+
         public void Next (bool restart)
         {
+            Next (restart, true);
+        }
+        
+        public void Next (bool restart, bool userRequested)
+        {
             CancelErrorTransition ();
             
             Source = NextSource;
             raise_started_after_transition = true;
 
-            player_engine.IncrementLastPlayed ();
+            if (userRequested) {
+                player_engine.IncrementLastPlayed ();
+            }
             
-            if (Source is IBasicPlaybackController && ((IBasicPlaybackController)Source).Next (restart)) {
+            if (Source is IBasicPlaybackController && ((IBasicPlaybackController)Source).Next (restart, userRequested)) {
             } else {
-                ((IBasicPlaybackController)this).Next (restart);
+                ((IBasicPlaybackController)this).Next (restart, userRequested);
             }
             
             OnTransition ();
@@ -261,29 +278,20 @@
             return true;
         }
         
-        bool IBasicPlaybackController.Next (bool restart)
+        bool IBasicPlaybackController.Next (bool restart, bool userRequested)
         {
-            TrackInfo tmp_track = CurrentTrack;
+            if (CurrentTrack != null) {
+                previous_stack.Push (CurrentTrack);
+            }
 
-            if (next_stack.Count > 0) {
-                CurrentTrack = next_stack.Pop ();
-                if (tmp_track != null) {
-                    previous_stack.Push (tmp_track);
-                }
-            } else {
-                TrackInfo next_track = QueryTrack (Direction.Next, restart);
-                if (next_track != null) {
-                    if (tmp_track != null) {
-                        previous_stack.Push (tmp_track);
-                    }
+            CurrentTrack = CalcNextTrack (Direction.Next, restart);
+            if (CurrentTrack != null) {
+                if (userRequested) {
+                    QueuePlayTrack ();
                 } else {
-                    return true;
+                    player_engine.SetNextTrack (CurrentTrack);
                 }
-                
-                CurrentTrack = next_track;
             }
-            
-            QueuePlayTrack ();
             return true;
         }
         
@@ -293,20 +301,27 @@
                 next_stack.Push (current_track);
             }
 
-            if (previous_stack.Count > 0) {
-                CurrentTrack = previous_stack.Pop ();
-            } else {
-                TrackInfo track = CurrentTrack = QueryTrack (Direction.Previous, restart);
-                if (track != null) {
-                    CurrentTrack = track;
-                } else {
-                    return true;
-                }
+            CurrentTrack = CalcNextTrack (Direction.Previous, restart);
+            if (CurrentTrack == null) {
+                QueuePlayTrack ();
             }
             
-            QueuePlayTrack ();
             return true;
         }
+
+        private TrackInfo CalcNextTrack (Direction direction, bool restart)
+        {
+            if (direction == Direction.Previous) {
+                if (previous_stack.Count > 0) {
+                    return previous_stack.Pop ();
+                }
+            } else if (direction == Direction.Next) {
+                if (next_stack.Count > 0) {
+                    return next_stack.Pop ();
+                }
+            }
+            return QueryTrack (direction, restart);
+        }
         
         private TrackInfo QueryTrack (Direction direction, bool restart)
         {

=== modified file 'src/Extensions/Banshee.InternetRadio/Banshee.InternetRadio/InternetRadioSource.cs'
--- src/Extensions/Banshee.InternetRadio/Banshee.InternetRadio/InternetRadioSource.cs	2009-02-09 21:28:02 +0000
+++ src/Extensions/Banshee.InternetRadio/Banshee.InternetRadio/InternetRadioSource.cs	2009-09-29 02:43:39 +0000
@@ -279,8 +279,20 @@
             return false;
         }
         
-        public bool Next (bool restart)
+        public bool Next (bool restart, bool userRequested)
         {
+            /*
+             * TODO: It should be technically possible to handle userRequested=False
+             * correctly here, but the current implementation is quite hostile.
+             * For the moment, just SetNextTrack (null), and go on to OpenPlay if
+             * the engine isn't currently playing.
+             */
+            if (!userRequested) {
+                ServiceManager.PlayerEngine.SetNextTrack ((SafeUri)null);
+                if (ServiceManager.PlayerEngine.IsPlaying ()) {
+                    return true;
+                }
+            }
             RadioTrackInfo radio_track = ServiceManager.PlaybackController.CurrentTrack as RadioTrackInfo;
             if (radio_track != null && radio_track.PlayNextStream ()) {
                 return true;

=== modified file 'src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/StationSource.cs'
--- src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/StationSource.cs	2009-05-15 01:59:16 +0000
+++ src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/StationSource.cs	2009-09-29 02:43:39 +0000
@@ -294,17 +294,24 @@
 
         bool IBasicPlaybackController.First ()
         {
-            return ((IBasicPlaybackController)this).Next (false);
+            return ((IBasicPlaybackController)this).Next (false, true);
         }
         
         private bool playback_requested;    
-        bool IBasicPlaybackController.Next (bool restart)
+        bool IBasicPlaybackController.Next (bool restart, bool userRequested)
         {
             TrackInfo next = NextTrack;
-            if (next != null) {
-                ServiceManager.PlayerEngine.OpenPlay (next);
-            }  else {
-                playback_requested = true;
+            if (userRequested) {
+                if (next != null) {
+                    ServiceManager.PlayerEngine.OpenPlay (next);
+                }  else {
+                    playback_requested = true;
+                }
+            } else {
+                // We want to unconditionally SetNextTrack.
+                // Passing null is OK.
+                ServiceManager.PlayerEngine.SetNextTrack (next);
+                playback_requested = next == null;
             }
             return true;
         }
@@ -372,7 +379,7 @@
 
                             if (playback_requested) {
                                 if (this == ServiceManager.PlaybackController.Source ) {
-                                    ((IBasicPlaybackController)this).Next (false);
+                                    ((IBasicPlaybackController)this).Next (false, true);
                                 }
                                 playback_requested = false;
                             }

=== modified file 'src/Extensions/Banshee.PlayQueue/Banshee.PlayQueue/PlayQueueSource.cs'
--- src/Extensions/Banshee.PlayQueue/Banshee.PlayQueue/PlayQueueSource.cs	2009-09-14 16:57:53 +0000
+++ src/Extensions/Banshee.PlayQueue/Banshee.PlayQueue/PlayQueueSource.cs	2009-09-29 08:41:52 +0000
@@ -478,10 +478,10 @@
 
         bool IBasicPlaybackController.First ()
         {
-            return ((IBasicPlaybackController)this).Next (false);
+            return ((IBasicPlaybackController)this).Next (false, true);
         }
         
-        bool IBasicPlaybackController.Next (bool restart)
+        bool IBasicPlaybackController.Next (bool restart, bool userRequested)
         {
             if (current_track != null && ServiceManager.PlayerEngine.CurrentTrack == current_track) {
                 int index = TrackModel.IndexOf (current_track) + 1;
@@ -492,14 +492,21 @@
                 ServiceManager.PlaybackController.Source = PriorSource;
                 if (was_playing) {
                     ServiceManager.PlaybackController.PriorTrack = prior_playback_track;
-                    ServiceManager.PlaybackController.Next (restart);
+                    ServiceManager.PlaybackController.Next (restart, userRequested);
                 } else {
+                    if (!userRequested) {
+                        ServiceManager.PlayerEngine.SetNextTrack ((TrackInfo)null);
+                    }
                     ServiceManager.PlayerEngine.Close ();
                 }
                 return true;
             }
 
-            ServiceManager.PlayerEngine.OpenPlay (current_track);
+            if (userRequested) {
+                ServiceManager.PlayerEngine.OpenPlay (current_track);
+            } else {
+                ServiceManager.PlayerEngine.SetNextTrack (current_track);
+            }
             return true;
         }
         

