public Spotify() { InitializeComponent(); // Setup API api = new SpotifyAPI(SpotifyAPI.GetOAuth(), "reptail.dk"); cfid = api.CFID; if (cfid.error != null) { UpdateData(); this.Focus(); } else { _error = true; lblSongName.Text = "Unknown error..."; } }
public void Dispose() { lcd.Dispose(); cfid = null; api = null; spotTimer.Enabled = false; spotTimer.Dispose(); spotTimer = null; lcdTimer.Enabled = false; lcdTimer.Dispose(); lcdTimer = null; refreshTimer.Enabled = false; refreshTimer.Dispose(); refreshTimer = null; initExcpt = null; }
public Spotify() { cfid = API.CFID; Current_Status = API.Status; }
public Server() { // Default message. Console.WriteLine( "This is the CampFire listener, if you keep this running in the background with Spotify open it will play tracks when they are recieved by the webpage.\r\n"); _api = new SpotifyAPI(SpotifyAPI.GetOAuth(), "SpotifyServer.spotilocal.com"); _currentStatus = _api.Status; _cfid = _api.CFID; FleckLog.Level = LogLevel.Debug; var allSockets = new List<IWebSocketConnection>(); var server = new WebSocketServer("ws://localhost:8181/CampFire"); server.Start(socket => { socket.OnOpen = () => { Console.WriteLine("Open connection."); // Add the new connection to our list so we can send messages back. allSockets.Add(socket); }; socket.OnClose = () => { Console.WriteLine("Closed connection, the CampFire webpage has been closed."); // Make sure we remove them from out list when we are not connected to em. allSockets.Remove(socket); }; socket.OnMessage = message => { // When a message is recieved it comes in the from NAME^spotify:track:oiasdoijasd so we split the string with ^ to get the name and uri. string[] details = message.Split('^'); // Don't ask why we have to do this, if we don't it borks. heh. string username = Convert.ToString(details[0]); string uri = Convert.ToString(details[1]); // Set our spotify to look at the new uri and then play it _api.URI = uri; _currentStatus = _api.Play; string trackName = _currentStatus.track.track_resource.name; string artistName = _currentStatus.track.artist_resource.name; // Message all users that X user has played X, we have to do this because there is no other way of telling the other people connecting WHO played what song allSockets.ToList().ForEach(s => s.Send(username + " played " + trackName + " - " + artistName)); Console.WriteLine("Playing: " + _currentStatus.track.track_resource.name + " - " + _currentStatus.track.artist_resource.name); }; }); var inpt = Console.ReadLine(); if (inpt != "exit") { Console.ReadLine(); } }
public static bool Init() { bool ret = false; try { _API = new SpotifyAPI(SpotifyAPI.GetOAuth(), "127.0.0.1"); //It's required to get the contents of API.CFID before doing anything, even if you're not intending to do anything with the CFID _cfid = _API.CFID; if (_cfid.error != null) { throw new Exception(string.Format("Spotify returned a error {0} (0x{1})", _cfid.error.message, _cfid.error.type)); } _Current_Status = _API.Status; if (_cfid.error != null) { throw new Exception(string.Format("Spotify returned a error {0} (0x{1})", _cfid.error.message, _cfid.error.type)); } _tmr = new Timer() { Interval = 5000, Enabled = true }; _tmr.Elapsed += _tmr_Elapsed; _tmr.Start(); ret = true; } catch (Exception ex) { Debug.WriteLine(ex.Message); ret = false; } return ret; }
public static void Dispose() { _API = null; _cfid = null; _tmr.Stop(); }
private void InitSpot() { try { api = new SpotifyAPI(SpotifyAPI.GetOAuth()); cfid = api.CFID; initExcpt = null; } catch (Exception e) { initExcpt = e; } }
// Attempt to acquire the Spotify resources private void setupSpotify() { m_spotifyApiInstance = new SpotifyAPI(SpotifyAPI.GetOAuth(), "jariz-example.spotilocal.com"); m_cfid = m_spotifyApiInstance.CFID; if (m_cfid.error != null) { Console.WriteLine(string.Format("Spotify returned a error {0} (0x{1})", m_cfid.error.message, m_cfid.error.type)); // Thread.Sleep(-1); } else { // it was ok } }