Ejemplo n.º 1
0
        /// <summary>
        /// Called when the connection state of the session is updated.
        /// If the session is logged in, all present playlists are added and
        /// listeners are attached to the playlist collection list.
        /// </summary>
        async void ConnectionstateUpdated(Session sender, SessionEventArgs e) {

            switch (sender.ConnectionState) {

                // Logged out
                case ConnectionState.LoggedOut:

                    if (_previousConnectionState == ConnectionState.LoggedIn) {
                        
                        // Remove all playlists
                        MasterPlaylist.Instance.Dispose();
                        var playlists = Touchee.Medium.Local.Containers.OfType<Spotify.Media.Playlist>();
                        lock (playlists) {
                            foreach (var playlist in playlists)
                                playlist.Dispose();
                        }
                    }

                    break;

                // Offline state (when logged in, but not completely yet)
                case ConnectionState.Offline:
                    break;

                // User has logged in
                case ConnectionState.LoggedIn:

                    // Save the master playlist
                    MasterPlaylist.Instance.Save();

                    // Wait for the playlist container
                    await _session.PlaylistContainer;

                    // Track initial set of playlists and starred list
                    Log("PL: " + _session.PlaylistContainer.Playlists.Count);
                    this.AddPlaylists(_session.PlaylistContainer.Playlists);
                    this.AddPlaylist(_session.Starred);

                    // Add event handler for removal/adding of playlists
                    _session.PlaylistContainer.Playlists.CollectionChanged += Playlists_CollectionChanged;

                    break;
                    
                // User has been disconnected after having been logged in
                case ConnectionState.Disconnected:
                    break;

                // No clue
                case ConnectionState.Undefined:
                    break;

            }

            _previousConnectionState = sender.ConnectionState;

        }
Ejemplo n.º 2
0
        /// <summary>
        /// Called when the Session connection status is updated
        /// </summary>
        async void ConnectionstateUpdated(Session sender, SessionEventArgs e) {
            Log("Spotify: Connection state: " + sender.ConnectionState.ToString());
            this.OnStateUpdated();

            switch (sender.ConnectionState) {
                
                // Logged out
                case ConnectionState.LoggedOut:
                    break;

                // Offline state (when logged in, but not completely yet)
                case ConnectionState.Offline:
                    break;

                // User has logged in
                case ConnectionState.LoggedIn:
                    break;

                // User has been disconnected after having been logged in
                case ConnectionState.Disconnected:
                    break;

                // No clue
                case ConnectionState.Undefined:
                    throw new NotImplementedException();

            }

        }
Ejemplo n.º 3
0
 /// <summary>
 /// Called when the credentials blob has been updated from the Spotify session.
 /// Stores the username and these credentials into the Spotify plugin config.
 /// </summary>
 void Session_CredentialsBlobUpdated(Session sender, SessionEventArgs e) {
     Plugin.Config.Set("username", sender.UserName);
     Plugin.Config.Set("credentials", e.Message);
     Plugin.Config.Save();
 }
Ejemplo n.º 4
0
		static void HandleOnPlaylistContainerLoaded(Session sender, SessionEventArgs e)
		{
			Console.WriteLine("PlaylistContainer loaded, {0} lists", sender.PlaylistContainer.CurrentLists.Length);

            // Here you attach event handlers to PlaylistContainer and all the current lists in it
		}	
Ejemplo n.º 5
0
 void HandleOnLoginComplete(Session sender, SessionEventArgs e)
 {
     #if DEBUG
     if (Log.IsDebugEnabled) Log.Debug("HandleOnLoginComplete");
     #endif
     try
     {
     #if DEBUG
         if (Log.IsDebugEnabled) Log.Debug("Login result: " + e.Status);
     #endif
         _loginOk = Session.ConnectionState == sp_connectionstate.LOGGED_IN;
         _loggedIn.Set();
     }
     catch (Exception ex)
     {
     #if DEBUG
         if (Log.IsErrorEnabled)
             Log.Error("Exception", ex);
     #endif
     }
 }
Ejemplo n.º 6
0
 void HandleOnEndOfTrack(Session sender, SessionEventArgs e)
 {
     #if DEBUG
     if (Log.IsDebugEnabled)
         Log.Debug("End of music delivery.");
     #endif
     try
     {
         LameEncoder.Close();
         LameEncoder = null;
         _playbackDone.Set();
     }
     catch (Exception ex)
     {
     #if DEBUG
         if (Log.IsErrorEnabled)
             Log.Error("Exception", ex);
     #endif
     }
 }
Ejemplo n.º 7
0
 static void HandleOnConnectionError(Session sender, SessionEventArgs e)
 {
     #if DEBUG
     if (Log.IsErrorEnabled)
         Log.Error("Connection error: " + e.Status);
     #endif
 }
Ejemplo n.º 8
0
        void SpotifySession_OnEndOfTrack(Session sender, SessionEventArgs e)
        {
            //Console.WriteLine("End of music delivery. Flushing player buffer...");
            Thread.Sleep(1500); // Samples left in player buffer. Player lags 500 ms

            playbackDone.Set();

            try
            {

                NextTrack();
            }
            catch
            {

            }
            //	Console.WriteLine("Playback complete");
        }
Ejemplo n.º 9
0
		static void HandleOnConnectionError(Session sender, SessionEventArgs e)
		{
			Console.WriteLine("Connection error: " + e.Status);
		}
Ejemplo n.º 10
0
		static void HandleOnLoggedOut(Session sender, SessionEventArgs e)
		{	
			playbackDone.Set();
			loggedOut.Set();
		}
Ejemplo n.º 11
0
		static void HandleOnLogMessage(Session sender, SessionEventArgs e)
		{
			Console.WriteLine("Log: " + e.Message);
		}		
Ejemplo n.º 12
0
		static void HandleOnMessageToUser(Session sender, SessionEventArgs e)
		{			
			Console.WriteLine("Message: " + e.Message);
		}
Ejemplo n.º 13
0
		static void HandleOnPlayTokenLost(Session sender, SessionEventArgs e)
		{
			Console.Out.WriteLine("Play token lost");
			playbackDone.Set();
		}
Ejemplo n.º 14
0
		static void HandleOnEndOfTrack(Session sender, SessionEventArgs e)
		{
			Console.WriteLine("End of music delivery. Flushing player buffer...");
			Thread.Sleep(510); // Samples left in player buffer. Player lags 500 ms
			player.Stop();
			player = null;
			Console.WriteLine("Playback complete");
			playbackDone.Set();
		}
Ejemplo n.º 15
0
        void SpotifySession_OnPlaylistContainerLoaded(Session sender, SessionEventArgs e)
        {
            foreach(Spotify.Playlist PlsList in SpotifySession.PlaylistContainer.CurrentLists)
            {
                //toBeAdded.Enqueue(PlsList);

            }
        }
Ejemplo n.º 16
0
 void SpotifySession_OnConnectionError(Session sender, SessionEventArgs e)
 {
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Called when a connection error occurs
 /// </summary>
 void ConnectionError(Session sender, SessionEventArgs e)
 {
     Log("Spotify: Connection Error: " + e.Error.ToString(), Logger.LogLevel.Error);
 }
Ejemplo n.º 18
0
        void SpotifySession_OnPlaylistContainerLoaded(Session sender, SessionEventArgs e)
        {
            if (playlists == null)
            {
                playlists = new List<MediaChrome.Views.Playlist>();
            }
                foreach (Spotify.Playlist _Playlist in SpotifySession.PlaylistContainer.CurrentLists)
                {
                    MediaChrome.Views.Playlist D = new MediaChrome.Views.Playlist(this, _Playlist.Name,_Playlist.LinkString, Host);
                    D.ID = _Playlist.LinkString;
                    D.Title = _Playlist.Name;

                    playlists.Add(D);
                }
                playlistLoaded = true;
        }
Ejemplo n.º 19
0
 /// <summary>
 /// Called when the credentials blob has been updated from the Spotify session.
 /// Stores the username and these credentials into the Spotify plugin config.
 /// </summary>
 void Session_CredentialsBlobUpdated(Session sender, SessionEventArgs e)
 {
     Plugin.Config.Set("username", sender.UserName);
     Plugin.Config.Set("credentials", e.Message);
     Plugin.Config.Save();
 }
Ejemplo n.º 20
0
 static void HandleOnMessageToUser(Session sender, SessionEventArgs e)
 {
     #if DEBUG
     if (Log.IsInfoEnabled)
         Log.Info("Spotify says: " + e.Message);
     #endif
 }
Ejemplo n.º 21
0
        void Program_SpotifySession_OnLoginComplete(Session sender, SessionEventArgs e)
        {
            if(e.Status == sp_error.OK)
            {
                this.DialogResult= DialogResult.OK;
                //this.Close();

            }
            else
            {
                //label6.Text = e.Status.ToString();
                panel1.Show();
            }
        }
Ejemplo n.º 22
0
 void HandleOnLoggedOut(Session sender, SessionEventArgs e)
 {
     #if DEBUG
     if (Log.IsDebugEnabled) Log.Debug("HandleOnLoggedOut");
     #endif
     try
     {
         _playbackDone.Set();
         _loggedOut.Set();
     }
     catch (Exception ex)
     {
     #if DEBUG
         if (Log.IsErrorEnabled)
             Log.Error("Exception", ex);
     #endif
     }
 }
Ejemplo n.º 23
0
 /// <summary>
 /// Called when a connection error occurs
 /// </summary>
 void ConnectionError(Session sender, SessionEventArgs e) {
     Log("Spotify: Connection Error: " + e.Error.ToString(), Logger.LogLevel.Error);
 }
Ejemplo n.º 24
0
 void HandleOnPlayTokenLost(Session sender, SessionEventArgs e)
 {
     #if DEBUG
     if (Log.IsWarnEnabled) Log.Warn("Play token lost");
     #endif
     _playbackDone.Set();
 }
Ejemplo n.º 25
0
		// Event callbacks
		
		static void HandleOnLoginComplete(Session sender, SessionEventArgs e)
		{
			Console.WriteLine("Login result: " + e.Status);			
			Console.WriteLine("Searching for 'green day idiot'... ");
			
			
			// RequestId can be whatever. It's never used internally.
			// If several searches are active at the same time, it can be used
			// too tell them apart.
			sender.Search("green day idiot", 0, 500, 0, 500, 0, 500, null);
		}