/// <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; }
/// <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(); } }
/// <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(); }
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 }
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 } }
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 } }
static void HandleOnConnectionError(Session sender, SessionEventArgs e) { #if DEBUG if (Log.IsErrorEnabled) Log.Error("Connection error: " + e.Status); #endif }
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"); }
static void HandleOnConnectionError(Session sender, SessionEventArgs e) { Console.WriteLine("Connection error: " + e.Status); }
static void HandleOnLoggedOut(Session sender, SessionEventArgs e) { playbackDone.Set(); loggedOut.Set(); }
static void HandleOnLogMessage(Session sender, SessionEventArgs e) { Console.WriteLine("Log: " + e.Message); }
static void HandleOnMessageToUser(Session sender, SessionEventArgs e) { Console.WriteLine("Message: " + e.Message); }
static void HandleOnPlayTokenLost(Session sender, SessionEventArgs e) { Console.Out.WriteLine("Play token lost"); playbackDone.Set(); }
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(); }
void SpotifySession_OnPlaylistContainerLoaded(Session sender, SessionEventArgs e) { foreach(Spotify.Playlist PlsList in SpotifySession.PlaylistContainer.CurrentLists) { //toBeAdded.Enqueue(PlsList); } }
void SpotifySession_OnConnectionError(Session sender, SessionEventArgs e) { }
/// <summary> /// Called when a connection error occurs /// </summary> void ConnectionError(Session sender, SessionEventArgs e) { Log("Spotify: Connection Error: " + e.Error.ToString(), Logger.LogLevel.Error); }
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; }
static void HandleOnMessageToUser(Session sender, SessionEventArgs e) { #if DEBUG if (Log.IsInfoEnabled) Log.Info("Spotify says: " + e.Message); #endif }
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(); } }
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 } }
void HandleOnPlayTokenLost(Session sender, SessionEventArgs e) { #if DEBUG if (Log.IsWarnEnabled) Log.Warn("Play token lost"); #endif _playbackDone.Set(); }
// 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); }