private void PlayTrack(object[] args)
        {
            string trackId = (string) args[0];
            int position = (int)args[1];

            var track = new Track("spotify:track:" + trackId);

            var error = Session.LoadPlayer( track.TrackPtr );

            if (error != libspotify.sp_error.OK)
            {
                SpotifyEnabledBrowser.Singleton.SendTrackFailedMessage(error.ToString());
                return;
            }

            lastLoadedTrackPtr = track.TrackPtr;

            if (position > 500) // fix: we'd rather lose the last 0.5 secs than the first (was >0)
            {
                Session.Seek(position);
            }

            Session.Play();

            // should be loaded, now check if it's starred
            if (libspotify.sp_track_is_starred(Session.SessionPtr, track.TrackPtr))
            {
                Log.Debug("track is starred? "); // this is called for every track - bug in libspotify???

               // SpotifyEnabledBrowser.Singleton.SendCurrentlyPlayingTrackIsStarred();
            }
        }
        private void StarTrack(object[] args)
        {
            var trackId = (string)args[0];

            //IntPtr ptr = AllocateIntArray(5);
            var track = new Track("spotify:track:" + trackId);

               Log.Debug("trackPtr: " + track.TrackPtr.ToString());

            IntPtr unmanagedPointer = IntPtr.Zero;
            try
            {
                // marshal track pointer into an unmanaged array  (starring api call needs an array of track pointers)
                IntPtr[] ids = new IntPtr[1] {track.TrackPtr};

                unmanagedPointer = Marshal.AllocHGlobal(ids.Length);
                Marshal.Copy(ids, 0, unmanagedPointer, ids.Length);

                lock (Session._lock)
                {
                    var error = libspotify.sp_track_set_starred(Session.SessionPtr, unmanagedPointer,
                                                                1, true);

                    if (error != libspotify.sp_error.OK)
                    {
                        SpotifyEnabledBrowser.Singleton.SendTrackFailedMessage("Unable to star: " + error.ToString());
                        return;
                    }
                }
            }
            finally
            {
                if(unmanagedPointer!=IntPtr.Zero)
                    Marshal.FreeHGlobal(unmanagedPointer);
            }
        }
        private void PlayTrack(object[] args)
        {
            var trackId = (string) args[0];
            var position = (int) args[1];
            Track track = null;
            AccessViolationException accessViolationException;
            do
            {
                try
                {
                    track = new Track("spotify:track:" + trackId);

                    var error = Session.LoadPlayer(track.TrackPtr);

                    if (error != libspotify.sp_error.OK)
                    {
                        Console.WriteLine(Properties.Resources.MainWindow_PlayTrack_Could_not_play);
                        return;
                    }

                    accessViolationException = null;
                }
                catch (AccessViolationException ex)
                {
                    accessViolationException = ex;
                    Thread.Sleep(TimeSpan.FromSeconds(1));
                }
            } while (accessViolationException != null);

            if (position > 500) // fix: we'd rather lose the last 0.5 secs than the first (was >0)
            {
                Session.Seek(position);
            }

            Session.Play();
            _statusModel.CurrentTrack = track;
        }