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.UpdateLastPlayed ();
next_track_set.Reset ();
pending_uri = null;
next_track_pending = true;
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");
next_track_set.Set ();
}
}